-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathex.Rd
53 lines (49 loc) · 1.37 KB
/
ex.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Data_handling.R
\name{ex}
\alias{ex}
\title{Extract Parts of an Object with Varnames and Units Attributes}
\usage{
ex(x, i, j, drop = TRUE)
}
\arguments{
\item{x}{An atomic type or a data frame. Object from which to extract
element(s).}
\item{i, j}{Indices specifying elements to extract as specified in
\code{\link{Extract}}.}
\item{drop}{A logical value. If \code{TRUE} (default), the result is coerced
to the lowest possible dimension.}
}
\value{
A vector or data frame with \code{varnames} and \code{units}
attributes.
}
\description{
Conserves \code{varnames} and \code{units} attributes of vectors and data
frames during extraction.
}
\details{
Extraction from atomic types is done as \code{x[i]} ignoring \code{j} and
\code{drop} (applies also to matrices and arrays). Extraction from data
frames is done as \code{x[i, j, drop]}.
}
\examples{
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)
}
\seealso{
\code{\link{Extract}}, \code{\link{drop}} and
\code{\link{varnames}}.
}