Skip to Content

nlevels {base}

The Number of Levels of a Factor
Package: 
base
Version: 
R 3.0.2

Description

Return the number of levels which its argument has.

Usage

nlevels(x)

Arguments

x
an object, usually a factor.

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.

Values

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

See Also

levels, factor.

Examples

nlevels(gl(3, 7)) # = 3

Documentation reproduced from R 3.0.2. License: GPL-2.