Transforms columns in dataframe by the specified methods. Separate methods can be applied for categorical column transformation and numerical column transformation.

column_transformer(
  x_train,
  x_test,
  column_list,
  num_trans = "standard_scaling",
  cat_trans = "onehot_encoding"
)

Arguments

x_train

training set dataframe/tibble

x_test

test set dataframe/tibble

column_list

named list of categorical and numeric columns.

num_trans

method(character) for numerical transformation - Can take values "standard_scaling" or "minmax_scaling" (default = "standard_scaling")

cat_trans

method(character) for categorical transformation - Cant take values "onehot_encoding" or "label_encoding" (default = "onehot_encoding")

Value

A list with named items x_train and x_list that have been transformed according to the arguments specified

Examples

x_train <- data.frame('x' = c(2.5, 3.3, 5,8), 'y' = factor(c(1, 6, 1,6))) x_test <- data.frame('x' = c(2,1), 'y' = factor(c(1,6))) column_transformer(x_train, x_test, list("numeric" = c('x'), "categorical" = c('y')))
#> $x_train #> x y.6 #> 1 -0.9036857 0 #> 2 -0.5750727 1 #> 3 0.1232299 0 #> 4 1.3555286 1 #> #> $x_test #> x y.6 #> 1 -1.109069 0 #> 2 -1.519835 1 #>