Arrange tabular or non-tabular datasets into groups according to a specified key function.
Now registered in General
The basic principle of FlexiGroups
is that the result of a grouping operation is always a collection of groups, and each group is a collection of elements. Groups are typically indexed by the grouping key.
Thatβs similar to the group(...)
interface in SplitApplyCombine.jl
, see differences in the README.
This interface makes FlexiGroups
compatible and composable with a wide range of collection and table types, and with generic data processing functions such as map
and filter
from Base
.
Companion packages following similar design approaches: FlexiMaps and FlexiJoins.
The main workhorse is the group
function:
group([keyf=identity], X; [restype=Dictionary])
, it groups elements of X
by keyf(x)
, returning a mapping of keys to lists of values in each group:
julia> using FlexiGroups
julia> xs = 3 .* [1, 2, 3, 4, 5]
julia> g = group(isodd, xs)
2-element Dictionary
true β [3, 9, 15]
false β [6, 12]
The result is an (ordered) Dictionary
by default, but can be changed to the base Dict
or another dictionary type. Alternatively to dictionaries, specifying restype=KeyedArray
(from AxisKeys.jl
) results in a KeyedArray
. Its axiskeys
are the group keys.
For details and more features/examples:
- views,
- margins,
- pivot tables,
- by-group transformations,
see the docs.