[R] deleting column from data frame

Marianne Promberger marianne.promberger at kcl.ac.uk
Tue Feb 23 17:08:22 CET 2010


Hi Knut,

> test <- data.frame("X"=c(1:4),"Y"=c(5:8),"Z"=c(8:11))
> test <- test[,-2]
> 
> Is there a way to specify the col name  "Y" to delete instead the number?


test[,colnames(test)!="Y"] 

test[,!colnames(test)%in%"Y"] 

test[,-grep("Y",colnames(test))]

bw,                                  
Marianne

-- 
Marianne Promberger PhD, King's College London
http://promberger.info
R version 2.10.1 (2009-12-14)
Ubuntu 9.10



More information about the R-help mailing list