lset | R Documentation |
Set values in an lvec
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, ...)
x |
|
... |
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 |
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.