oneHotEncoder: Encode a vector into a one hot data.frame

Description Usage Arguments Value Examples

View source: R/variableencoding.R

Description

This function takes a vector of items and onehot encodes them into a data.frame which in reality is a tibble. Every unique value of the vector get converted into a column and the value is 1 for that column if the row number matches the position in the original vector. See the examples for details.

Usage

1
oneHotEncoder(x, f = function(y) y)

Arguments

x

the vector to convert to a one hot

f

a function to apply to x before encoding which defaults to identity

Value

the one hot encoded data.frame with the original data given in a Data column

Examples

1
2
3
4
5
6
library(lubridate)
oneHotEncoder(
  x = seq(as.Date("2017-01-01"), by = "day", length.out = 10),
  f = function(x) wday(x, label = TRUE)
)
oneHotEncoder(x = wday(seq(as.Date("2017-10-07"), by = "days", length.out = 10), label = TRUE))

DoktorMike/datools documentation built on Feb. 28, 2021, 8:39 a.m.