replace_at | R Documentation |
Try to find and replace elements at given indices and signal an
error if not found, unless it is stated to explicitly add the element (see
option add
).
replace_at(.x, ...) ref_replace_at(.x, ...) ## S3 method for class 'Container' replace_at(.x, ..., .add = FALSE) ## S3 method for class 'Container' ref_replace_at(.x, ..., .add = FALSE) ## S3 method for class 'dict.table' replace_at(.x, ..., .add = FALSE) ## S3 method for class 'dict.table' ref_replace_at(.x, ..., .add = FALSE)
.x |
any |
... |
either name = value pairs or two vectors/lists with names/values to be replaced. |
.add |
|
replace_at
uses copy semantics while ref_replace_at
works by
reference.
For Container
, an object of class Container
(or one of the
respective derived classes).
For dict.table
an object of class dict.table
.
co = container(a = 0, b = "z") replace_at(co, a = 1, b = 2) replace_at(co, 1:2, 1:2) # same replace_at(co, c("a", "b"), list(1, 2)) # same try({ replace_at(co, x = 1) # names(s) not found: 'x' }) replace_at(co, x = 1, .add = TRUE) # ok (adds x = 1) dit = dict.table(a = 1:3, b = 4:6) replace_at(dit, a = 3:1) replace_at(dit, 1, 3:1) # same replace_at(dit, "a", 3:1) # same replace_at(dit, a = 3:1, b = 6:4) replace_at(dit, 1:2, list(3:1, 6:4)) # same try({ replace_at(dit, x = 1) # column(s) not found: 'x' }) replace_at(dit, x = 1, .add = TRUE) # ok (adds column)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.