Search notes:

R object attribute

A variable can have zero, one or more attributes.
An attribute is simply a name-value pair.
For example, a matrix stores its dimension in an attribute named dim. The value of this dim is a vector with two elements (rows and columns).
The attributes of a variable can be queried with attributes and str.
A specific name-value pair can be set or queried with attr().
Specially treated attributes (attribute names) are:

colnames

Matrices can have the colnames attribute set.

dimensions

The dimension attribute can be used to turn vectors and lists into matrices.
See dim()

names

See names() and setNames().

rownames

Matrices can have the rownames attribute set.

class

An object might have a class attribute which should be a character vector. If this attribute is present, it contains the names of the classes from which this object inherits.
This value tells various R methods what to do with the variable (for example plot).
class prints the vector of names of the class attribute.

See also

R Objects

Index