varnames: Object Attributes Varnames and Units

View source: R/Data_handling.R

varnamesR Documentation

Object Attributes Varnames and Units

Description

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.

Usage

varnames(x, names = FALSE)

varnames(x) <- value

units(x, names = FALSE)

units(x) <- value

Arguments

x

A data frame or an atomic type.

names

A logical value. Applies only in case of data frames. If TRUE, attributes are extracted with corresponding column names.

value

An atomic type that represents varnames or units. The length must be 1 if x is an atomic type or equal to number of columns in x if x is a data frame.

Details

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 "-".

Value

For varnames and units, a character vector.

For varnames<- and units<-, the updated object x.

See Also

read_eddy and write_eddy.

Examples

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)

lsigut/openeddy documentation built on Aug. 5, 2023, 12:25 a.m.