[R] extract columns from a dataframe

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jul 5 15:02:08 CEST 2004

myDF[! names(myDF) %in% not_wanted]

if I understand you aright.  E.g.

hills[! names(hills) %in% "climb"]

which can also be done by

subset(hills, select=-climb)

On Mon, 5 Jul 2004, Rado Bonk wrote:

> I'm coming back to R after while. I have a data frame with 200 columns, 
> each column has a name. How to extract all columns to a new dataset, but 
> the specified (by names) ones?

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 mailing list