lget: Apply getElement over a list

Description Usage Arguments Value Examples

View source: R/lget.R

Description

lget or lgetElement applies getElement to a list using lapply. sget and sgetElement do the same thing with sapply.

Usage

1
2
3
4
5
6
7
lget(X, name)

lgetElement(X, name)

sget(X, name, simplify = TRUE, USE.NAMES = TRUE)

sgetElement(X, name, simplify = TRUE, USE.NAMES = TRUE)

Arguments

X

A list.

name

A literal character string or a name (possibly backtick quoted). For extraction, this is normally (see under ‘Environments’) partially matched to the names of the object.

simplify

logical or character string; should the result be simplified to a vector, matrix or higher dimensional array if possible? For sapply it must be named and not abbreviated. The default value, TRUE, returns a vector or matrix if appropriate, whereas if simplify = "array" the result may be an array of “rank” (=length(dim(.))) one higher than the result of FUN(X[[i]]).

USE.NAMES

logical; if TRUE and if X is character, use X as names for the result unless it had names already. Since this argument follows ... its name cannot be abbreviated.

Value

A list (lget) or vector (sget) of the same length as X with the name parts of each element of X.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
e1 = list(x = rnorm(5),
          y = letters[c(1:2, 2:1, 3)],
          z = c(TRUE, TRUE, FALSE, TRUE, TRUE)
)
e2 = list(x = rnorm(5),
          y = letters[c(1:4, 1)],
          z = c(FALSE, TRUE, FALSE, TRUE, FALSE))
X = list(e1, e2)
lget(X, name = "x")
sget(X, name = "y")

smerc documentation built on Oct. 1, 2021, 5:07 p.m.