[R] REmove level with zero observations
GL
pflugg at shands.ufl.edu
Tue Aug 3 22:50:30 CEST 2010
If I have a column with 2 levels, but one level has no remaining
observations. Can I remove the level?
Had intended to do it as listed below, but soon realized that even though
there are no observations, the level is still there.
For instance
summary(dbs3.train.sans.influential.obs$HAC)
yields
0 ,1
4685,0
nlevels(dbs3.train.sans.influential.obs$HAC)
yields
[1] 2
drop.list <- NULL
for (i in 1:ncol(dbs3.train.sans.influential.obs)) {
if (nlevels(dbs3.train.sans.influential.obs[,i]) < 2) {drop.list <-
cbind(drop.list,i)}}
yields
nothing because HAC still has two levels, even though there aren't any
observations in on of the levels.
What I want to do is loop through all columns that are factors and create a
list of items to drop because there will subsequently be < 2 levels when I
try to run a linear model.
--
View this message in context: http://r.789695.n4.nabble.com/REmove-level-with-zero-observations-tp2312553p2312553.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list