nlevels

The number of levels of a factor, in their current order

x = factor(letters[1:5])
levels(x)
# [1] "a" "b" "c" "d" "e"
nlevels(x)
# [1] 5