Description Usage Arguments Details Value Examples
Split a vector or a list into groups, given a predicate function.
1 2 3 |
x |
a vector or a list to split into groups. |
predicate |
a binary function returning a boolean value. |
na.rm |
if x is atomic, delete missing values before grouping. |
predicate
will be applied to 2 adjacent elements. If it evaluates to
TRUE
, those elements belong to the same group, otherwise they belong
to different groups.
Grouping on equality is the most natural approach, therefore group_eq
is a convenient shortcut defined as
group_if(x, predicate = `==`)
for an atomic vector;
group_if(x, predicate = identical)
for a list.
group_if
(resp. group_eq
) is inspired by groupBy
(resp.
group
) in Haskell.
Note that group_if
behaves a little differently : while in
Haskell, the comparison is made with the first element in the group, in this
R-version the comparison is made with the adjacent element.
The operator %on% may be helpful to create a predicate with readable syntax.
A list where each element is a group (flattening this list should give back the same values in the same order). Element names are kept.
1 2 3 4 5 6 7 8 9 10 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.