Re: [R] Problem subsetting: undefined columns

2011-12-02 Thread Aurélien PHILIPPOT
thanks Michael. I played with your suggestion to get the output in the format I wanted, and I found the following that works fine: sub<-d[, which(colnames(d) %in% v) ] Aurelien 2011/12/2 R. Michael Weylandt < michael.weyla...@gmail.com> > How about this? > > d[, v[v %in% colnames(d)]] > > Mich

Re: [R] Problem subsetting: undefined columns

2011-12-02 Thread R. Michael Weylandt
How about this? d[, v[v %in% colnames(d)]] Michael On Dec 2, 2011, at 12:01 PM, Aurélien PHILIPPOT wrote: > Hi Paul and Jim, > Thanks for your messages. > > I just wanted R to give me the columns of my data frame d, whose names > appear in v. I do not care about the names of v that are not i

Re: [R] Problem subsetting: undefined columns

2011-12-02 Thread Aurélien PHILIPPOT
Hi Paul and Jim, Thanks for your messages. I just wanted R to give me the columns of my data frame d, whose names appear in v. I do not care about the names of v that are not in d. In addition, every time, there will be at least one element of v that has a corresponding column in d, for sure, so I

Re: [R] Problem subsetting: undefined columns

2011-12-02 Thread Paul Hiemstra
On 12/02/2011 07:20 AM, Aurélien PHILIPPOT wrote: > Dear R-users, > -I am new to R, and I am struggling with the following problem. > > -I am repeating the following operations hundreds of times, within a loop: > I want to subset a data frame by columns. I am interested in the columns > names that

Re: [R] Problem subsetting: undefined columns

2011-12-02 Thread Jim Holtman
?try If you know that you might have a problem with undefined columns, or whatever, then trap the error with 'try' so your program can recover. You could also validate the data that you are going to use before entering the loop; standard defensive programming - errors are always going to happe

[R] Problem subsetting: undefined columns

2011-12-02 Thread Aurélien PHILIPPOT
Dear R-users, -I am new to R, and I am struggling with the following problem. -I am repeating the following operations hundreds of times, within a loop: I want to subset a data frame by columns. I am interested in the columns names that are given by the rows of another data frame that was built i