R/dropEmptyLevels.R

Defines functions dropEmptyLevels

Documented in dropEmptyLevels

dropEmptyLevels <- function(x)
#	Drop levels of a factor that don't occur
#	Gordon Smyth
#	Created 25 March 2012.  Last modified 6 March 2015.
{
	if(is.factor(x)) {
		i <- which(tabulate(as.integer(x))>0L)
		if(length(i) < nlevels(x)) x <- factor(x, levels=levels(x)[i])
		return(x)
	} else {
		return(factor(x))
	}
}

Try the edgeR package in your browser

Any scripts or data that you put into this service are public.

edgeR documentation built on March 18, 2018, 2:35 p.m.