Re: [R] select columns from vector of column names

2010-07-09 Thread MacQueen, Don
How about data[ , colnames] Or data[ , colnames[1]] data[ , colnames[2]] -Don On 7/9/10 11:27 AM, "Jonathan Flowers" wrote: > Hi > > I want to extract columns from a data frame using a vector with the desired > column names. > > This short example uses the select argument in the subse

Re: [R] select columns from vector of column names

2010-07-09 Thread Horace Tso
How about data[,colnames(data)%in%colnames] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Flowers Sent: Friday, July 09, 2010 11:27 AM To: r-help@r-project.org Subject: [R] select columns from vector of column names

[R] select columns from vector of column names

2010-07-09 Thread Jonathan Flowers
Hi I want to extract columns from a data frame using a vector with the desired column names. This short example uses the select argument in the subset function to accomplish what I am trying to do. Is there a better solution? #names of desired columns colnames <- c("col1","col3") #my data data