A mungebit which takes a fixed group of columns and produces a new
group of columns (or a single new column) can be abstracted into a
multi-column transformation. This functions allows one to specify what
happens to a fixed list of columns, and the mungebit will be the
resulting multi-column transformation applied to an arbitrary combination
of columns. An arity-1 multi-column transformation with a single output
column equal to its original input column is simply a
column_transformation
.
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.
multi_column_transformation(transformation, nonstandard = FALSE)
transformation | function. The function's first argument will
receive atomic vectors derived from some |
---|---|
nonstandard | logical. If |
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
.
The function produced by calling multi_column_transformation
will
not run independently. It must be used a train or predict function for
a mungebit
.
column_transformation
, standard_column_format
divider <- multi_column_transformation(function(x, y) { x / y }) # Determines the ratio of Sepal.Length and Sepal.Width in the iris dataset. iris2 <- mungebit$new(divider)$run(iris, c("Sepal.Length", "Sepal.Width"), "Sepal.Ratio")