[R] referring to a data-frame column using a variable

Don MacQueen macq at llnl.gov
Tue Nov 13 00:59:54 CET 2007


Or

   dat[,c1]

-Don

At 8:49 AM +1300 11/13/07, Rolf Turner wrote:
>On 13/11/2007, at 8:42 AM, Bernd Jagla wrote:
>
>>  Hi,
>>
>>
>>
>>  I would like to refer to a column in a data frame using a variable. 
>>  How
>>  would I do this?
>>
>>
>>
>>  Something like:
>>
>>
>>
>>  c1<-"column1"
>>
>>  dat${c1}
>>
>>
>>
>>  where names(dat) includes 'column1'
>
>	Use dat[[c1]].
>
>		cheers,
>
>			Rolf Turner
>
>######################################################################
>Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062



More information about the R-help mailing list