Session Ready
Exercise

Attributes

You have made it to the last exercise in the course! Congrats! Let's finish up with an easy one.

Attributes are a bit of extra metadata about your data structure. Some of the most common attributes are: row names and column names, dimensions, and class. You can use the attributes() function to return a list of attributes about the object you pass in. To access a specific attribute, you can use the attr() function.

Exploring the attributes of cash:

attributes(cash)

$names
[1] "company"   "cash_flow" "year"     

$row.names
[1] 1 2 3 4 5 6 7

$class
[1] "data.frame"

attr(cash, which = "names")

[1] "company"   "cash_flow" "year"     
Instructions
100 XP
  • The matrix my_matrix and the factor my_factor are defined for you.
  • Use attributes() on my_matrix.
  • Use attr() on my_matrix to return the "dim" attribute.
  • Use attributes() on my_factor.