remove columns in a dataframe in r

To remove columns in a dataframe in R, you can use the "subset" function or the indexing operator "[,]".

Here's an example using the indexing operator to remove the "column_to_remove" from the "my_data" dataframe:

main.r
my_data <- my_data[, -column_to_remove]
40 chars
2 lines

Alternatively, you can use the "subset" function to remove the same column:

main.r
my_data <- subset(my_data, select = -c(column_to_remove))
58 chars
2 lines

In both cases, "column_to_remove" refers to the name or index of the column you want to remove.

gistlibby LogSnag