lset: Set values in an lvec

Description Usage Arguments Details Examples

View source: R/lset.R

Description

Set values in an lvec

Usage

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

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

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

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

Arguments

x

lvec to set values in

...

used to pass additional arguments to other methods

index

a numeric or logical vector with indices at which the values should be set.

values

a vector with the new values. When shorter than the length of the indices the values are recycled.

range

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

Details

Should behave in the same way as assigning and indexing to a regular R-vector. The range given by range includes both end elements. So, a range of c(1,3) selects the first three elements.

When range is given, and values is not given it is assumed index contains the values. Therefore, one can do lset(x, range = c(1,4), NA), to set the first four elements of x to missing.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
a <- as_lvec(1:10)
# set second element to 20
lset(a, 2, 20)
print(a)
# set odd elements to 20
lset(a, c(TRUE, FALSE), 20)
print(a)
# values are recycled
lset(a, 1:4, 100:101)
print(a)
# range index; set first 3 elements to NA
lset(a, range = c(1,3), NA)
print(a)

djvanderlaan/lvec documentation built on Oct. 31, 2017, 8:39 a.m.