attr {base} | R Documentation

## Object Attributes

### Description

Get or set specific attributes of an object.

### Usage

    attr(x, which)
    attr(x, which) <- value

### Arguments

`x` | an object whose attributes are to be accessed.
`which` | a character string specifying which attribute is to be accessed.
`value` | an object, the new value of the attribute.

### Value

These functions provide access to a single attribute of an object. The first form returns the value of the named attribute. The replacement form causes the named attribute to take the value specified.
The first form first looks for an exact match to `which` amongst the attributes of `x`, then a partial match. If no exact match is found and more than one partial match is found, the result is `NULL`.
Note that some attributes (namely `class`, `comment`, `dim`, `dimnames`, `names` and `tsp`) are treated specially and have restrictions on the values which can be set.

### References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

### See Also

`attributes`

### Examples

    # create a 2 by 5 matrix
    x <- 1:10
    attr(x,"dim") <- c(2, 5)

[Package base version 2.3.1 Index]