ID EN
Miscellaneous

nlevels

R Base 3.6.2

Return the number of levels which its argument has.

Syntax

R
nlevels(x)

Arguments

Parameter Description
x an object, usually a factor.

Return Value

The length of levels(x), which is zero if x has no levels.

Details

This is usually applied to a factor, but other objects can have levels. The actual factor levels (if they exist) can be obtained with the levels function.

Examples

Example
R
# NOT RUN {
nlevels(gl(3, 7)) # = 3
# }

See Also

levels factor.