Learn R Programming

lvec (version 0.2.5)

lget: Read elements from an lvec

Description

Read elements from an lvec

Usage

lget(x, ...)

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

# S3 method for default lget(x, index = NULL, range = NULL, ...)

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

Value

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

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.

Examples

Run this code
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))

Run the code above in your browser using DataLab