[R] erase columns

Rau, Roland Rau at demogr.mpg.de
Tue Sep 14 10:59:40 CEST 2004


Hi, 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of michele lux
Sent: Dienstag, 14. September 2004 10:44
To: r-help at r-project.org
Subject: [R] erase columns

Can somebody remember me which is the command to erase
columns from a data frame?
Thanks Michele

I hope the following code-piece helps what you are looking for:

mydf <- as.data.frame(matrix(runif(100),ncol=5))

### if you want to erase the third column, do:
mydf <- mydf[,-3]


mydf2 <- as.data.frame(matrix(runif(100),ncol=20))

### if you want to erase the first, third and twentieth column, do:
mydf2 <- mydf2[,-c(1,5,20)]

Ciao,
Roland


+++++
This mail has been sent through the MPI for Demographic Rese...{{dropped}}




More information about the R-help mailing list