lget: Read elements from an lvec

Description Usage Arguments Details Value Examples

View source: R/lget.R

Description

Read elements from an lvec

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
lget(x, ...)

## S3 method for class 'lvec'
lget(x, index = NULL, range = NULL, ...)

## Default S3 method:
lget(x, index = NULL, range = NULL, ...)

## S3 method for class 'data.frame'
lget(x, index = NULL, range = NULL, ...)

Arguments

x

the lvec to read from

...

used to pass on additional arguments to other methods.

index

a logical or numeric vector to index x with

range

a numeric vector of length 2 specifying a range of elements to select. Specify either index or range.

Details

Indexing using index should follow the same rules as indexing a regular R-vector using a logical or numeric index. The range given by range includes both end elements. So, a range of c(1,3) selects the first three elements.

Value

Returns an lvec with the selected elements. In order to convert the selection to an R-vector as_rvec can e used.

Examples

1
2
3
4
5
6
7
8
a <- as_lvec(letters[1:4])
# Select first two elements
lget(a, 1:2)
lget(a, c(TRUE, TRUE, FALSE, FALSE))
lget(a, range = c(1,2))

# Logical indices are recycled: select odd elements
lget(a, c(TRUE, FALSE))

lvec documentation built on May 2, 2019, 8:16 a.m.