Learn R Programming

base (version 3.2.1)

nlevels: The Number of Levels of a Factor

Description

Return the number of levels which its argument has.

Usage

nlevels(x)

Arguments

x
an object, usually a factor.

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.

See Also

levels, factor.

Examples

Run this code
nlevels(gl(3, 7)) # = 3

Run the code above in your browser using DataLab