View source: R/Data_handling.R
ex | R Documentation |
Conserves varnames
and units
attributes of vectors and data
frames during extraction.
ex(x, i, j, drop = TRUE)
x |
An atomic type or a data frame. Object from which to extract element(s). |
i , j |
Indices specifying elements to extract as specified in
|
drop |
A logical value. If |
Extraction from atomic types is done as x[i]
ignoring j
and
drop
(applies also to matrices and arrays). Extraction from data
frames is done as x[i, j, drop]
.
A vector or data frame with varnames
and units
attributes.
Extract
, drop
and
varnames
.
xx <- data.frame(lengths = 1:3, areas = 4:6)
varnames(xx) <- c("lengths", "areas")
units(xx) <- c("m", "m2")
str(xx)
# extract specified rows and columns
str(ex(xx, 1:2, 1:2))
# extract specified rows
str(ex(xx, 1))
# extract specified columns
str(ex(xx, , 1))
# extract without dropping current class
ex(xx, , 1, drop = FALSE)
# extract elements of a vector
ex(xx$lengths, 2:3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.