[R] column extraction by name ?

Simon Fear Simon.Fear at synequanon.com
Wed Nov 12 15:25:17 CET 2003


Uh oh! Time for my occasional reminder post to use subset(), 
as in

subset(df, select = -z)

for this case.


> -----Original Message-----
> From: ryszard.czerminski at pharma.novartis.com
> [mailto:ryszard.czerminski at pharma.novartis.com]
> Sent: 12 November 2003 12:51
> To: R-help list
> Subject: [R] column extraction by name ?
> 
> 
> Security Warning: 
> If you are not sure an attachment is safe to open please contact  
> Andy on x234. There are 0 attachments with this message. 
> ________________________________________________________________ 
>  
> I have a data frame (df) with colums x, y and z.
> e.g.  df <- data.frame(x = sample(4), y = sample(4), z = sample(4))
> I can extract column z by: df$z or df[3]
> I can also extract columns x,y by: df[1:2] or by df[-3].
> 
> Is it possible to extract x,y columns in a "symbolic" fashion i.e.
> by equivalent of df[-z] (which is illegal) ???
> 
> Or alternativeley, is there an equivalent of "index" function,
> which would return index of the column given name ?
> 
> Ryszard
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>  
 
Simon Fear 
Senior Statistician 
Syne qua non Ltd 
Tel: +44 (0) 1379 644449 
Fax: +44 (0) 1379 644445 
email: Simon.Fear at synequanon.com 
web: http://www.synequanon.com 
  
Number of attachments included with this message: 0 
  
This message (and any associated files) is confidential and\...{{dropped}}




More information about the R-help mailing list