[R] Subset doesn't drop unused factor levels

Sundar Dorai-Raj sundar.dorai-raj at PDF.COM
Thu Oct 7 20:02:55 CEST 2004



hadley wickham wrote:

> a <- data.frame(b = rep(1:5, each=2), c=factor(rep("a",10), levels=c("a","b")))
> levels(subset(a, b=1, drop=T)$c)
> # [1] "a" "b"
> 
> Is this a bug?
> 

Also, I think you meant:

levels(subset(a, b==1, drop=T)$c)

(Note the double-equals for logical equality)

--sundar




More information about the R-help mailing list