[R] extract columns using their names

Wolski wolski at molgen.mpg.de
Thu May 27 16:28:51 CEST 2004


?subset

*********** REPLY SEPARATOR  ***********

On 5/27/2004 at 5:19 PM Adrian Dusa wrote:

>Hello,
>
>Is there a way to extract multiple columns from a dataframe using their
>names instead of their numbers?
>
>Currently I use:
>
>data2 <- data1[, c(1,3,9)]
>
>And I am looking for something like
>
>data2 <- data1[, c("XX","YY","ZZ")]
>
>
>I use the same dataframe for many purposes, and I run codes that change
>the order of the columns every time.
>
>Many thanks,
>Adrian
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Adrian Dusa (adi at roda.ro)
>Romanian Social Data Archive (www.roda.ro)
>1, Schitu Magureanu Bd.
>050025 Bucharest sector 5
>Romania
>Tel./Fax: +40 (21) 312.66.18\ 
>              +40 (21) 312.02.10/ int.101
>
>______________________________________________
>R-help at 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



Dipl. bio-chem. Eryk Witold Wolski    @    MPI-Moleculare Genetic   
Ihnestrasse 63-73 14195 Berlin       'v'    
tel: 0049-30-83875219               /   \    
mail: wolski at molgen.mpg.de        ---W-W----    http://www.molgen.mpg.de/~wolski




More information about the R-help mailing list