[R] REmove level with zero observations

Allan Engelhardt allane at cybaea.com
Thu Aug 5 16:46:55 CEST 2010


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 helps

Allan



More information about the R-help mailing list