[R] levels of factor when subsetting the factor
    Roger D. Peng 
    rdpeng at gmail.com
       
    Tue Sep 12 17:36:47 CEST 2006
    
    
  
I think you want 'fact[1:6, drop = TRUE]'
-roger
Afshartous, David wrote:
>  
> All,
> 
> When I take a subset of a factor the reduced factor still maintains all
> the original levels of the factor when say forming the key in a plot.
> The data is correct, but the variable still "remembers" the original
> levels.  See below for reproducible code.  Does anyone know how to fix
> this?
> cheers,
> dave
> 
> fact = as.factor(c(rep("A", 3),rep("B", 3), rep("C", 3)))
> new.fact = fact[1:6]
>> new.fact
> [1] A A A B B B
> Levels: A B C    ## should only show A B
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
-- 
Roger D. Peng  |  http://www.biostat.jhsph.edu/~rpeng/
    
    
More information about the R-help
mailing list