Hi all!

I am trying to drop columns from a data frame dynamically depending on user
input. The dataframe whose columns need to be dropped is called "Finaldata"
So here is what I do:

V is a dataframe with columns v1 and v2 as follows

   v1          v2
1   1      Shape
2   0       Length
3   0       Rate

v1 corresponds to user input, 1 if you want to drop the column, 0 otherwise
v2 corresponds to column names of the all the columns in "Finaldata"
I then use following code to drop columns

for (i in 1:3)
  {
    if(V$v1[i]==1)
    {
      print(V$v2[i])
      Finaldata<-subset(Finaldata,select=-c(V$v2[i]))
    }

  }

However v2 being type character is not accepted by subset.
I read subset needs column names without quotes.
I tried stripping off quotes through gsub and cat,however it din't help
There are lot of columns and I cannot perform this individually on all
columns.
How do i go about it?


Thanks!
SB

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to