map_values: Map values of variables.

Description Usage Arguments Details Examples

Description

Map values of variables.

Usage

1
map_values(vars, mapping, rename)

Arguments

vars

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

mapping

The mapping to apply. This should be a named vector, where the names are the old values, and the elements are the new values. There should be at most one unnamed element, representing 'all other' elements.

func

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

Details

Currently, this function always turns the mapped variables into factors.

Examples

1
2
3
4
5
6
df <- data.frame(a=c(1,2,NA,3), b=c(10,20,30,NA), c=c("c1", "c2", "c3", "c4"))
prep <- map_values("c", c(c1="C1", c4="C4", "other"))
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.