File: dropEmptyLevels.R

package info (click to toggle)
r-bioc-edger 3.40.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,484 kB
  • sloc: cpp: 1,425; ansic: 1,109; sh: 21; makefile: 5
file content (13 lines) | stat: -rw-r--r-- 318 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
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))
	}
}