FunctionXform {pmmlTransformations} | R Documentation |
Add a function transformation to a WrapData object.
Description
Add a function transformation to a WrapData object.
Usage
FunctionXform(boxdata, origFieldName, newFieldName = "newField",
newFieldDataType = "numeric", formulaText, mapMissingTo = NA)
Arguments
boxdata |
wrapper object obtained by using the WrapData function on raw data |
origFieldName |
string specifying name(s) of the original data field(s) being used in the transformation |
newFieldName |
name of the new field created by the transformation |
newFieldDataType |
data type of the new field created by the transformation |
formulaText |
string expression specifying the transformation |
mapMissingTo |
value to be given to the transformed variable if the value of any input variable is missing |
Details
Calculate the expression provided
in formulaText for every row in the boxdata$data
data frame. The formulaText
argument must represent
a valid R expression, and any functions used in
formulaText
must be defined in the current
environment.
The name of the new field is optional (a default name is provided), but an error will be thrown if attempting to create a field with a name that already exists in the WrapData object.
Value
R object containing the raw data, the transformed data and data statistics.
The data
data frame will contain a new newFieldName
column, and
fieldData
will contain a new newFieldName
row.
Author(s)
Dmitriy Bolotov
See Also
Examples
# Load the standard iris dataset
data(iris)
# Wrap the data
irisBox <- WrapData(iris)
# Perform a transform on the Sepal.Length field:
# the value is squared and then divided by 100
irisBox <- FunctionXform(irisBox,origFieldName="Sepal.Length",
newFieldName="Sepal.Length.Transformed",
formulaText="(Sepal.Length^2)/100")
# Combine two fields to create another new feature:
irisBox <- FunctionXform(irisBox,
origFieldName="Sepal.Width, Petal.Width",
newFieldName="Width.Sum",
formulaText="Sepal.Width + Sepal.Length")
# Create linear model using the derived features
fit <- lm(Petal.Length ~
Sepal.Length.Transformed + Width.Sum, data=irisBox$data)
# Create pmml from the fit
# library(pmml)
# fit_pmml <- pmml(fit, transform=irisBox)