Dear List, When I subset a data.frame, the levels are not re-adjusted (see example). Why is this? Am I missing out on some basic stuff here?
Thanks Ulrik > m <- data.frame(gender = c("M", "M","F"), ht = c(172, 186.5, 165), wt = > c(91,99, 74)) > dim(m) [1] 3 3 > levels(m$gender) [1] "F" "M" > s <- subset(m, m$gender == "M") > dim(s) [1] 2 3 > levels(s$gender) [1] "F" "M" > cat <- sapply(s, is.factor); s[cat] <- lapply(s[cat], factor) > dim(s) [1] 2 3 > levels(s$gender) [1] "M" ______________________________________________ R-help@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.