[R] select different variables from a list of data frames
Simon Kiss
sjkiss at gmail.com
Mon Nov 12 23:34:53 CET 2012
Hi:
How do I select different variables from a list of data frames.
I have a list of 13 that looks like below. Each data frame has more variables than I need. How do I go through the list and select the variables that I need.
In the example below, I need to get the variables "a", and "q10" and "q14" to be returned to two separate data frames.
Thank you.
Yours, Simon Kiss
#####Sample data
mylist<-list(df1=data.frame(a=seq(1,10,1), c=seq(1,109,1), q10=rep('favour', 10)), df2=data.frame(a=seq(1,10,1), b=seq(15,24,1), q14=rep('favour', 10)))
#The variables with different names that I need are
q<-c('q10', 'q14')
#My current code
dat<-mapply(function(x,y) {
data.frame(a=x$a, y$q)
}, x=mylist, y=q)
More information about the R-help
mailing list