fuse_one_hot: Take a set of one hot encoded columns (values: 0 or 1) and...

Description Usage Arguments Examples

Description

Take a set of one hot encoded columns (values: 0 or 1) and transform them back into a single factor column.

Usage

1
2
fuse_one_hot(vars, out = ".out", missing = "missing", as.integer = FALSE,
  keep = FALSE)

Arguments

vars

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

out

Name of the new column

missing

Value to use for the rows where all the one hot columns are zero.

as.integer

Whether the output should be integer (or character).

keep

Should the original one hot encoded column be kept

Examples

1
2
3
4
5
6
df <- data.frame(A=c("a1","a1","a2","a3"), B=c(1, 0, 0, 1), C=c(0, 1, 0, 0))
prep <- fuse_one_hot(vars = c('B', 'C'))
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.