Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.LNX.4.44.0305301706480.8311-100000@gannet.stats>
Date: 2003-05-30T16:10:15Z
From: Brian Ripley
Subject: How to remove a complete dataframe column
In-Reply-To: <114104136437.20030530165107@power.inescn.pt>

On Fri, 30 May 2003, Mark Marques wrote:

> I am using dataframes and I and I want to delete (remove) a specific
> column by name ...
> the data frame has 14 columns with several names and only need some.
> I tried to overwrite the columns with a single value but that in not very
> clean as I need to export the data to file.
> The rm command gives me a warning message stating :
> < remove: variable "rtu$Ri." was not found >
> or there is another method to remove parts of a dataframe?

You make a copy selecting the names you want, as in

rtu2 <- rtu[!(names(rtu) %in% c("Ri", "another I do not want"))]

or

rtu3 <- rtu[c("var2", "var7")]

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