Description Usage Arguments Examples
This function is a wrapper for replace()
that takes a vector or data frame
and replaces all instances matching a specified value or condition with a new value.
1 | ReplaceValues(data, old.val = NA, new.val = 0, condition = FALSE)
|
data |
Data frame or character vector to be manipulated |
old.val |
Current value to be found; defaults to |
new.val |
New value to take the place of found values; defaults to |
condition |
Whether or not to parse the input as a condition; defaults to
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Replace all NA with 0 (default behavior)
(dat <- c(-3:3, NA, NaN))
ReplaceValues(dat)
# Replace negative values with -Inf
ReplaceValues(dat, "<0", -Inf, condition=TRUE)
# Replace a with NA
set.seed(123)
(dat <- sample(letters[1:5], size=20, replace=TRUE))
ReplaceValues(dat, "a", NA)
# Replace a and e with "vowel"
ReplaceValues(dat, "%in% c('a', 'e')", "vowel", condition=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.