withNumericColumnFromFormula method
A new data frame with a column calculated from a formula.
Example:
print(sepals.withHead(5));
print(sepals.withHead(5).withNumericColumnFromFormula(
name: "geom_mean",
formula: "sqrt(sepal_width * sepal_length)",
));
.--.------------.-----------.
|id|sepal_length|sepal_width|
:--+------------+-----------:
|3 |4.7 |3.2 |
|4 |4.6 |3.1 |
|5 |5.0 |3.6 |
|6 |5.4 |3.9 |
|53|6.9 |3.1 |
'--'------------'-----------'
.--.------------.-----------.------------------.
|id|sepal_length|sepal_width|geom_mean |
:--+------------+-----------+------------------:
|3 |4.7 |3.2 |3.8781438859330635|
|4 |4.6 |3.1 |3.776241517699841 |
|5 |5.0 |3.6 |4.242640687119285 |
|6 |5.4 |3.9 |4.589117562233507 |
|53|6.9 |3.1 |4.624932431938871 |
'--'------------'-----------'------------------'
Implementation
DataFrame withNumericColumnFromFormula({
required String name,
required String formula,
}) {
if (!_columnNameOkay(name)) {
throw PackhorseError.badColumnName(name);
}
return copy..numericColumns[name] = NumericColumn(_formulaResults(formula));
}