Description Usage Arguments Value Examples
Replace
replaces the values in x
which are equal to
from
to the values given in to
. The values in to
are
recycled to match the length of from
.
1 | Replace(x, from, to, digits = 10L)
|
x |
a raw, integer, character or numeric (double) vector, or a factor |
from |
vector of elements to replace |
to |
the elements |
digits |
integer indicating the number of decimal places to be used in
the comparison of double values (ignored if |
a vector with replaced values
1 2 3 4 5 6 7 8 9 10 11 12 | x <- c(NA, c("a", "a", "z", "e", "q"))
# note that 'from' might contain values which are not present in 'x'
xr <- Replace(x, from = c("w", "a", "e"), to = c("ww", "aa", "ee"))
# only 'a' and 'e' were replaced
xr
stopifnot(identical(length(x), length(xr)))
stopifnot(identical(xr[c(2, 3, 5)], c("aa", "aa", "ee")))
# the missing value is not affected
stopifnot(is.na(xr[1]))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.