I have a number of columns that I would like to remove from a data frame. I know that we can delete them individually using something like:
df$x <- NULL <
Provide the data frame and a string of comma separated names to remove:
remove_features <- function(df, features) { rem_vec <- unlist(strsplit(features, ', ')) res <- df[,!(names(df) %in% rem_vec)] return(res) }
Usage:
remove_features(iris, "Sepal.Length, Petal.Width")