replace_values: Replace specific values in a column (usually NAs).

Description Usage Arguments Examples

Description

Replace specific values in a column (usually NAs).

Usage

1
2
replace_values(vars = numerics, values = NA, func, ...,
  rename = function(x) x)

Arguments

vars

Function or formula that returns selected columns from a data.frame. Alternatively, character vector of column names.

values

Vector of values to replace. Default is NA.

func

Function to do the replacement (e.g. mean, median). Can be a constant, a user defined function or a formula, where a dot represents the column.

...

Other arguments passed to func.

rename

Function to rename the output variables (input: the original column name, output: the new column name).

Examples

1
2
3
4
5
6
df <- data.frame(a=c(1,2,NA,4), b=c(10,20,40,NA), c=c("c1", "c2", "c3", "c4"))
prep <- replace_values(numerics, c(NA, 0), mean, na.rm = TRUE, rename = ~ paste(., "interim", sep="_"))
prep$fit(df)
prep$transform(df)
# or more succintly
prep$fit_transform(df)

rtsho/preprocessr documentation built on May 29, 2019, 8:58 a.m.