[R] subset columns from list with variable substitution

jween jween at rockwoodclinic.com
Fri May 25 20:09:34 CEST 2012


Hi there, I would like to use a list variable to select columns in a subset
from a parent table:

I have a data frame "table" with column headers a,b,c,d,e,x,y,z

and list variables

list1=c("a","b","c","d")
list2=c("a","b","x",y","z")
namelist=c("peter","paul","mary","jane")
group1=c("peter","paul")
group2=c("mary","jane")

I would like to subset "table" based on the list variable in a for loop:

for (i %in% namelist){
     if (i %in% group1){table2<-subset(table, select=list1)}
     else {{table2<-subset(table, select=list2)}
}

the "select=list1" syntax does not work. What would be the correct way to do
this?

Many Thanks

Jon

--
View this message in context: http://r.789695.n4.nabble.com/subset-columns-from-list-with-variable-substitution-tp4631374.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list