A factor in R is used to categorize a given data. The length of a factor in R is the number of items present in the factor.
To obtain the length or number of items present in a factor, we use the length()
function.
length(factor)
The length()
function takes the factor object as its single parameter value.
The length()
function returns the length of a given factor.
# creating a factor objectHeight <- factor(c("Tall", "Average", "Short", "Tall"))# implementing the length() functionlength(Height)
Height
using the factor()
function.Height
using the length()
function.