[R] column extraction by name ?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Nov 12 14:06:39 CET 2003
On Wed, 12 Nov 2003 ryszard.czerminski at pharma.novartis.com wrote:
> 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
> 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) ???
df[!(names(df) %in% "z")]
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help