nlevels {base}R Documentation

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.

Details

If the argument is not a factor, NA is returned.

The actual factor levels (if they exist) can be obtained with the levels function.

Examples

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

[Package base version 2.2.1 Index]