Re: [R] REmove level with zero observations

2010-08-05 Thread Allan Engelhardt
On 03/08/10 21:50, GL wrote: If I have a column with 2 levels, but one level has no remaining observations. Can I remove the level? Like this? d <- data.frame(a = factor(rep("A", 3), levels = c("A", "B"))) levels(d$a) # [1] "A" "B" d$a <- d$a[,drop=TRUE] levels(d$a) # [1] "A" Hope this h

Re: [R] REmove level with zero observations

2010-08-03 Thread GL
Ended up working as follows: dbs3.train.sans.influential.obs <- drop.levels(dbs3.train.sans.influential.obs) drop.list <- NULL for (i in 4:ncol(dbs3.train.sans.influential.obs)) { if (nlevels(dbs3.train.sans.influential.obs[,i]) < 2) {drop.list <- cbind(drop.list,i)}} dbs3.train.san

Re: [R] REmove level with zero observations

2010-08-03 Thread Bert Gunter
Actually, you probably want to remove the remaining level -- that is, remove the variable altogether, since if it has only a single value its effect is indistinguishable from the overall mean. Again, complying with the posting guide would be advisable. Bert Gunter Genentech Nonclinical Biostatist

Re: [R] REmove level with zero observations

2010-08-03 Thread Erik Iverson
GL wrote: If I have a column with 2 levels, but one level has no remaining observations. Can I remove the level? What is a 'column'? An element of a data.frame? Does the following help? f1 <- factor("L1", levels = c("L1", "L2")) levels(f1) f1 <- factor(f1) levels(f1) In absence of a repr

[R] REmove level with zero observations

2010-08-03 Thread GL
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) yie