From: Tony Plate <tplate_at_blackmesacapital.com>

Date: Fri 30 Jul 2004 - 05:40:58 EST

R-help@stat.math.ethz.ch 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 Received on Fri Jul 30 05:46:24 2004

Date: Fri 30 Jul 2004 - 05:40:58 EST

Seems to work fine for me if I understand correctly what you're trying to do (there are some typos in your message, which may mean I'm not understanding):

> data <- data.frame(x=1:3,y=4:6,z=7:9)
> data[c("x","y")]

x y

1 1 4

2 2 5

3 3 6

> mylist <- c("x","y")

> data[mylist]

x y

1 1 4

2 2 5

3 3 6

> data[,mylist]

x y

1 1 4

2 2 5

3 3 6

>

I'd generally use the second form of subsetting above (i.e., data[,mylist], because that will work with matrices as well).

hope this helps,

Tony Plate

At Thursday 01:22 PM 7/29/2004, 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
**>
**>______________________________________________
**>R-help@stat.math.ethz.ch 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
*

R-help@stat.math.ethz.ch 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 Received on Fri Jul 30 05:46:24 2004

*
This archive was generated by hypermail 2.1.8
: Wed 03 Nov 2004 - 22:55:21 EST
*