rattr | R Documentation |
Set and get attributes of the original R-vector stored in an lvec
rattr(x, which) rattr(x, which) <- value
x |
and object of type |
which |
a character vector of length one giving the name of the attribute. |
value |
the new value of the attribute |
The attributes of the lvec
can be set and obtained using the
standard functions attr
and attributes
. However
when an lvec is converted to an R-vector using, for example,
as_rvec
, the attributes of the resulting R-vector are set using
the result of rattr
. This can be used to store vectors such as
factors and dates (POSIXct) in lvec
objects, as these are basically
integer and numeric vectors with a number of additional attributes.
dates <- as_lvec(as.Date("2016-12-05", "2016-12-24")) # When printing and reading the result is converted back to a date object print(dates) as_rvec(dates) # make a factor of an integer lvec a <- as_lvec(1:3) rattr(a, "class") <- "factor" rattr(a, "levels") <- c("a", "b", "c") print(a)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.