I am going over the book Advanced R by Hadley. The book has a question which makes me really confused:
> structure(1:6, comment = "my attribute")
[1] 1 2 3 4 5 6
When you print that object you don't see the comment attribute. Why? Is the attribute missing, or is there something else special about it?
Could anyone help me understand what's going on here?
R's basic data structures include the vector, list, matrix, data frame, and factors. Some of these structures require that all members be of the same data type (e.g. vectors, matrices) while others permit multiple data types (e.g. lists, data frames). Objects may have attributes, such as name, dimension, and class.
Objects in R can have many properties associated with them, called attributes. These properties explain what an object represents and how it should be interpreted by R. Quite often, the only difference between two similar objects is that they have different attributes.
An attribute named "comment" is treated specially by R's default print
method. From ?comment
:
Description:
These functions set and query a _comment_ attribute for any R
objects. This is typically useful for ‘data.frame’s or model
fits.
Contrary to other ‘attributes’, the ‘comment’ is not printed (by
‘print’ or ‘print.default’).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With