[R] omitting columns from a data frame

Bill.Venables at csiro.au Bill.Venables at csiro.au
Tue Jun 21 23:54:27 CEST 2011


Suppose

names(xm1) <- c("alpha", "beta", "gamma", "delta")

then

xm2 <- subset(xm1, select = alpha:gamma)

or

xm2 <- subset(xm1, select = -delta)

will do the same job as xm1[, -4] 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Erin Hodgess
Sent: Tuesday, 21 June 2011 1:45 PM
To: R help
Subject: [R] omitting columns from a data frame

Dear R People:

I have a data frame, xm1, which has 12 rows and 4 columns.

If I put is xm1[,-4], I get all rows, and columns 1 - 3, which is as
it should be.

Now, is there a way to use the names of the columns to omit them, please?

Thanks so much in advance!

Sincerely,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodgess at gmail.com

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list