attributes(x) attributes(x) <- value
x
.
names(attributes(x))
is the vector of the names of
the attributes.
value
.
x
, and generally the class, are changed as a result
of the assignment
version of this function.
The attributes of
x
are set to the corresponding components of
value
and old attributes of
x
are deleted.
The class is usually changed to
"structure"
,
although some attributes
(for example,
"dim"
and
"levels"
)
result in other classes (such as
"array"
or
"matrix"
, and
"category"
).
names
(a
"names"
attribute) to a matrix or array
currently erases
"dim"
and
"dimnames"
attributes and changes a matrix
or array to a vector with class
"named"
.
value
has length
0
, all attributes are deleted.
Every data object receives two attributes ("length" and "mode")
simply by being defined. "Length" specifies the number of values in the
object and "mode" returns the type of object (eg. "numeric", "list",
"logical", "NULL"). "Length" and "mode" are implicit attributes.
However, the
attributes
function does not return any information on
implicit attributes. Use
length(x)
and
mode(x)
to retrieve
information on implicit attributes.
Other attributes may define various data types in the object ("dim")
or store
labels for data in the object ("dimnames" or "names"). This information
will be returned by the
attributes
function.
names(attributes(testscores)) # names of attributes of testscores attributes(testscores) attributes(foo) <- list(dim = c(2,4)) # coerces foo to a matrix