attr(x, which) attr(x, which) <- value
Other attributes may define various data types in the object ("dim") or store labels for data in the object ("dimnames" or "names").
For the attributes like dim that are known internally to S-PLUS, the assignment will only be accepted if it satisfies requirements for that attribute (for example, the length of x must equal the product of the dimensions). See the documentation for individual attributes. attr may also be used to set and get user-defined attributes. To explicitly delete the which attribute of x, use attr(x, which) <- NULL.
The semantics of attr are defined by saying that attr(x, which) is equivalent to attributes(x)[[which]] for either extracting or replacing attributes, with the restriction that which is interpreted as mode character. The value of attributes(x) is a list object (possibly of length 0) associated implicitly with any object x. See Subscript for the semantics of
This is a generic function; currently there are no methods for it.
For attributes known to S-PLUS, see the documentation for class, dim, dimnames, levels, names and tsp.
attr(iris, "dimnames") # equivalent to dimnames(iris)# a possible way to store documentation with x attr(x, "doc") <- doc.x