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 factor
Height <- factor(c("Tall", "Average", "Short"))
# Accessing the attributes of the factor object
attributes(Height)

Code explanation

  • Line 2: We create a factor variable Height using the factor() 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 Height we created has 3 levels, and is of the class factor object.

Free Resources