Sundar Dorai-Raj wrote:



Peter Wilkinson wrote:

This seems like such a trivial thing to do:

given a data.frame DF and variables w,v, x,y,z I can do

DF["x"] or DF[c("x","y")]

if I create a vector, mylist = c("x",y")

then I do DF[mylist]

I am not getting x and y, I get something else.


what is the correct way to subset a data.frame by columns using a vector, as if I were doing DF["x","y"]?


Peter

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


You want DF[, mylist]. DF[mylist] returns a list. You may want to look at "An Introduction to R", which covers this topic.


Sorry, typed too quickly.

DF[mylist] and DF[, mylist] are the same if mylist is a vector with more than one element.

After re-reading your post, I'm not quite sure what you are expecting. Sorry for any confusion....

--sundar

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to