r - delete specified columns in a data frame (the names of target columns are stored in a list) -


in data frame there many specified columns, want delete. stored target column names in list, , want eliminate using of this, maybe that's problem. didn't work:

for(i in 1:(length(columnnames))){  temp <- columnnames[i]  df$temp <- null  }  

because this:

print(ncol(df))  

i got original number of columns.

one way this

df <- data.frame(a = c("a","a","a"), b = c("b","b","b"), c = c("c","c","c")) # data set columnnames <- c("a", "b") # columns want erase df <- df[setdiff(names(df), columnnames)] 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -