withRowsWhereFormula method

DataFrame withRowsWhereFormula({
  1. required String formula,
  2. required bool predicate(
    1. num
    ),
})

A new data frame with rows selected based on a formula's results.

Example:

print(petals.withHead(5));
print(petals.withHead(5).withRowsWhereFormula(
  formula: "sqrt(petal_width * petal_length)",
  predicate: (result) => result > 1,
));

.--.------------.-----------.------------.
|id|petal_length|petal_width|species     |
:--+------------+-----------+------------:
|1 |1.4         |0.2        |setosa      |
|2 |1.4         |0.2        |setosa      |
|3 |1.3         |0.2        |setosa      |
|4 |1.5         |0.2        |setosa      |
|51|4.7         |1.4        |versicolor  |
'--'------------'-----------'------------'

.--.------------.-----------.------------.
|id|petal_length|petal_width|species     |
:--+------------+-----------+------------:
|51|4.7         |1.4        |versicolor  |
'--'------------'-----------'------------'

Implementation

DataFrame withRowsWhereFormula({
  required String formula,
  required bool Function(num) predicate,
}) {
  final values = _formulaResults(formula);
  return withRowsAtIndices([
    for (var i = 0; i < rowNumber; i++)
      if (predicate(values[i])) i
  ]);
}