[R] persistance of factor levels in a data frame

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.ac.be
Mon Feb 28 14:27:10 CET 2005


look at ?"[.data.frame" and also check this:

dat <- data.frame(V1=c(1:12), F1=rep(letters[1:3], each=4))
dat.ac <- dat[dat$F1 !="b", ]
###############
dat.ac$F1
dat.ac$F1[, drop=TRUE]
###############
dat.ac$F1 <- dat.ac$F1[, drop=TRUE]
levels(dat.ac$F1)

I hope it helps.

best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Lefebure Tristan" <Tristan.Lefebure at univ-lyon1.fr>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, February 28, 2005 2:07 PM
Subject: [R] persistance of factor levels in a data frame


> Hi,
> Just something I don't understand:
>
> data <- 
> data.frame(V1=c(1:12),F1=c(rep("a",4),rep("b",4),rep("c",4)))
> data_ac <- data[which(data$F1 !="b"), ]
> levels(data_ac$F1)
>
> Why the level "b" is always present ?
>
> thanks
>
> Tristan, R 2.0.1 for Linux Fedora 3
>
> -- 
> ------------------------------------------------------------
> Tristan LEFEBURE
> Laboratoire d'écologie des hydrosystèmes fluviaux (UMR 5023)
> Université Lyon I - Campus de la Doua
> Bat. Darwin C 69622 Villeurbanne - France
>
> Phone: (33) (0)4 26 23 44 02
> Fax: (33) (0)4 72 43 15 23
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list