A mungebit which affects multiple columns identically and independently can be abstracted into a column transformation. This function allows one to specify what happens to an individual column, and the mungebit will be the resulting column transformation applied to an arbitrary combination of columns.

column_transformation(transformation, nonstandard = FALSE)

Arguments

transformation

function. The function's first argument will receive an atomic vector derived from some data.frame. If the transformation has a name argument, it will receive the column name. Any other arguments will be received as the list(...) from calling the function produced by column_transformation.

nonstandard

logical. If TRUE, nonstandard evaluation support will be provided for the derived function, so it will be possible to capture the calling expression for each column. By default FALSE. Note this will slow the transformation by 0.1ms on each column.

Value

a function which takes a data.frame and a vector of column names (or several other formats, see standard_column_format) and applies the transformation.

Note

The function produced by calling column_transformation will not run independently. It must be used a train or predict function for a mungebit.

See also

multi_column_transformation, standard_column_format

Examples

doubler <- column_transformation(function(x) { 2 * x }) # doubles the Sepal.Length column in the iris dataset iris2 <- mungebit$new(doubler)$run(iris, c("Sepal.Length"))