ReplaceValues: Replace Values

Description Usage Arguments Examples

View source: R/format-data.R

Description

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.

Usage

1
ReplaceValues(data, old.val = NA, new.val = 0, condition = FALSE)

Arguments

data

Data frame or character vector to be manipulated

old.val

Current value to be found; defaults to NA

new.val

New value to take the place of found values; defaults to 0

condition

Whether or not to parse the input as a condition; defaults to FALSE

Examples

 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)

phively/wranglR documentation built on April 11, 2020, 5:12 a.m.