remove specific columns in a dataframe in r

To remove specific columns in a data frame, you can use the dplyr package in R. Specifically, you can use the select function to choose which columns to keep or remove. The select function includes a negative sign (-) to indicate which columns to remove.

Here's some example code that removes columns named "col1" and "col2" from a data frame called my_data:

main.r
library(dplyr)
my_data <- my_data %>%
  select(-col1, -col2)
61 chars
4 lines

This code selects all columns except "col1" and "col2" and assigns the resulting data frame back to my_data. You can modify this code to remove different columns as needed by changing the column names in the select function.

gistlibby LogSnag