Learn R Programming

collapse (version 1.5.0)

collapse-depreciated: Depreciated collapse Functions

Description

The functions Recode and replace_non_finite available until collapse v1.1.0 will be removed soon. Since v1.2.0, Recode is replaced by recode_num and recode_char and replace_non_finite is replaced by replace_Inf.

Usage

Recode(X, …, copy = FALSE, reserve.na.nan = TRUE, regex = FALSE)

replace_non_finite(X, value = NA, replace.nan = TRUE)

Arguments

X

a vector, matrix or data frame.

comma-separated recode arguments of the form: name = newname, `2` = 0, `NaN` = 0, `NA` = 0, `Inf` = NA, `-Inf` = NA, etc…

value

a single (scalar) value to replace matching elements with. Default is NA.

copy

logical. For reciprocal or sequential replacements of the form a = b, b = c make a copy of X to prevent a being replaced with b and then all b-values being replaced with c again. In general Recode does the replacements one-after the other, starting with the first.

reserve.na.nan

logical. TRUE identifies NA and NaN as special numeric values and does the correct replacement. FALSE will treat NA/NaN as strings, and thus not match numeric NA/NaN. Note: This is not an issue for Inf/-Inf, which are matched in both numeric and character variables.

regex

logical. If TRUE, all recode-argument names are (sequentially) passed to grepl as a pattern to search X. All matches are replaced.

replace.nan

logical. TRUE (default) replaces NaN/Inf/-Inf. FALSE replaces only Inf/-Inf.

See Also

Recode and Replace Values, Collapse Overview

Examples

Run this code
# NOT RUN {
Recode(c("a","b","c"), a = "b", b = "c")
Recode(c("a","b","c"), a = "b", b = "c", copy = TRUE)
Recode(c("a","b","c"), a = "b", b = "a", copy = TRUE)
Recode(month.name, ber = NA, regex = TRUE)
mtcr <- Recode(mtcars, `0` = 2, `4` = Inf, `1` = NaN)
replace_non_finite(mtcr)
replace_non_finite(mtcr, replace.nan = FALSE)
# }

Run the code above in your browser using DataLab