Select matching values with filter
filter(x, test) returns the elements of a collection for which a test callback is true. It keeps the original order and is useful for removing invalid observations, selecting thresholds, or narrowing a list before a calculation.
Example workflow
Filter measurements to retain values greater than zero, then use count to see how many remain or mean to summarize them. Use map when every value should be transformed rather than removed, and forEach for a callback intended for side effects.
Input caveats
The callback must return a meaningful Boolean-like decision and should not unexpectedly alter the source collection. Preserve index alignment when filtering paired data sets: applying a different test to each series can destroy correspondence before corr. For matrix slices, confirm the data structure first with size.