[R] Simple R Question...

Lars Bishop lars52r at gmail.com
Sat May 21 13:37:18 CEST 2011


Let's say I have the data frame 'dd' below. I'd like to select one
column from this data frame (say 'a') and keep its name in the
resulting data frame. That can be done as in #2. However, what if I
want to make my selection based on a vector of names (and again keep
those names in the resulting data frame). My attempt is #4 but doesn't
work.

dd <- data.frame(a = gl(3,4), b = gl(4,1,12), c=rnorm(12)) #1
data.frame("a" = dd[,"a"]) #2

mynames <- "a" #3
data.frame(eval(mynames) = dd[, mynames]) #4

thanks,
Lars.



More information about the R-help mailing list