Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dropEmptyLevels

Drop Levels of a Factor that Never Occur


Description

Reform a factor so that only necessary levels are kept.

Usage

dropEmptyLevels(x)

Arguments

x

a factor or a vector to be converted to a factor.

Details

In general, the levels of a factor, levels(x), may include values that never actually occur. This function drops any levels of that do not occur.

If x is not a factor, then the function returns factor(x). If x is a factor, then the function returns the same value as factor(x) or x[,drop=TRUE] but somewhat more efficiently.

Value

A factor with the same values as x but with a possibly reduced set of levels.

Author(s)

Gordon Smyth

See Also

Examples

x <- factor(c("a","b"), levels=c("c","b","a"))
x
dropEmptyLevels(x)

edgeR

Empirical Analysis of Digital Gene Expression Data in R

v3.32.1
GPL (>=2)
Authors
Yunshun Chen, Aaron TL Lun, Davis J McCarthy, Matthew E Ritchie, Belinda Phipson, Yifang Hu, Xiaobei Zhou, Mark D Robinson, Gordon K Smyth
Initial release
2021-01-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.