[R] remove levels from a factor

Frank E Harrell Jr f.harrell at vanderbilt.edu
Sat Aug 30 14:50:15 CEST 2008


Adrian Dusa wrote:
> Adrian Dusa <dusa.adrian <at> gmail.com> writes:
>>> [...snip...]
>>> f[which(f %in% names(table(f))[table(f) >= 2]), drop=TRUE]
>> [1] a a
>> Levels: a
> 
> Or, more simple:
> 
>> f[f %in% names(table(f))[table(f) >= 2], drop=TRUE]
> [1] a a
> Levels: a
> 
> Adrian

Also see the combine.levels function in the Hmisc package.
Frank

> 
> ______________________________________________
> R-help at r-project.org 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.
> 


-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list