What is the attributes() function in R?
Overview
The attributes() function in R is simply used to access an object’s attributes.
Syntax
attributes(x)
Parameter value
The attributes() function takes x as its parameter value, which represents any object in R.
Return value
The attributes() function returns an appropriately named list of attributes.
Code example
# creating a factorHeight <- factor(c("Tall", "Average", "Short"))# Accessing the attributes of the factor objectattributes(Height)
Code explanation
- Line 2: We create a factor variable
Heightusing thefactor()function. - Line 5: We use the
attribute()function to access the attributes of the factor object,Height.
Note: From the output of the code, we can see that the factor
Heightwe created has3levels, and is of the classfactorobject.