View source: R/Data_handling.R
varnames | R Documentation |
varnames
and units
are useful attributes that can store
original variable names (varnames
) and units of measurement
(units
) of each column in a data frame or of an atomic type. These
attributes can be extracted or assigned by following functions.
varnames(x, names = FALSE)
varnames(x) <- value
units(x, names = FALSE)
units(x) <- value
x |
A data frame or an atomic type. |
names |
A logical value. Applies only in case of data frames. If
|
value |
An atomic type that represents |
Functions check whether the extracted or assigned attributes contain elements
with NULL
, NA
, ""
values or if length of each element is
higher than 1
. In these cases, such elements are substituted with
"-"
.
For varnames
and units
, a character vector.
For varnames<-
and units<-
, the updated object x
.
read_eddy
and write_eddy
.
xx <- data.frame(a = 1, b = 2, c = 3, d = 4)
lapply(xx, attr, "units")
units(xx, names = TRUE)
varnames(xx) <- c("a", "", NA, "d")
units(xx) <- 1:4
str(xx)
units <- units(xx)
## NB: subsetting by rows removes 'varnames' and 'units' attributes
str(yy <- xx[1, ])
varnames(yy) <- names(yy)
units(yy) <- units
str(yy)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.