In R, there are different ways to remove a column from a dataframe using its name. One way is to use the subset()
function, which will return a dataframe without the selected columns:
main.r162 chars6 lines
Another way to remove columns is using indexing. We can select all the columns except the ones we want to remove by using a vector containing their names with a minus sign in front, and assigning it to the original dataframe:
main.r148 chars6 lines
Another very popular way to manipulate dataframes in R is by using the dplyr
package. A simple way to remove columns is by using the select()
function with the -
operator before the column names:
main.r193 chars9 lines
All of these methods achieve the same result, which is removing the selected column(s) from the original dataframe.
gistlibby LogSnag