[R] persistance of factor levels in a data frame

Douglas Bates bates at stat.wisc.edu
Mon Feb 28 14:31:39 CET 2005


Lefebure Tristan wrote:
> Hi,
> Just something I don't understand:
> 
> data <- data.frame(V1=c(1:12),F1=c(rep("a",4),rep("b",4),rep("c",4)))
> data_ac <- data[which(data$F1 !="b"), ]  
> levels(data_ac$F1)    
> 
> Why the level "b" is always present ?
> 
> thanks
> 
> Tristan, R 2.0.1 for Linux Fedora 3
> 

You must explicitly drop unused levels of a factor created by subsetting.

 > levels(data_ac$F1[drop = TRUE])
[1] "a" "c"




More information about the R-help mailing list