I have this in these cases of single columns
df = DataFrame(x = [1, 1, 2, 2], y = [1, 2, 101, 102]);
gd = groupby(df, :x);
julia> combine(gd,:x=>(X->Ref(X))=>:rx)
2×2 DataFrame
Row │ x rx
│ Int64 SubArray…
─────┼──────────────────
1 │ 1 [1, 1]
2 │ 2 [2, 2]
julia> combine(gd,:x=>(X->tuple(X...))=>:rx)
2×2 DataFrame
Row │ x rx
│ Int64 Tuple…
─────┼───────────────
1 │ 1 (1, 1)
2 │ 2 (2, 2)
Instead, if I try to extend to the case of multiple columns, I get this:
julia> combine(gd,[:x,:y]=>((X,Y)->[(tuple(X...),tuple(Y...))])=>[:rx,:ry])
2×3 DataFrame
Row │ x rx ry
│ Int64 Tuple… Tuple…
─────┼───────────────────────────
1 │ 1 (1, 1) (1, 2)
2 │ 2 (2, 2) (101, 102)
julia> combine(gd,[:x,:y]=>((X,Y)->[(Ref(X),Ref(Y))])=>[:rx,:ry])
2×3 DataFrame
Row │ x rx ry
│ Int64 RefValue… RefValue…
─────┼─────────────────────────────────────────────────────────────────────────────
1 │ 1 RefValue{SubArray{Int64,1,Array{… RefValue{SubArray{Int64,1,Array{…
2 │ 2 RefValue{SubArray{Int64,1,Array{… RefValue{SubArray{Int64,1,Array{…
using the vector form instead the result is
julia> combine(gd,[:x=>(X->Ref(extrema(X)))=>:rx,:y=>(X->Ref((sum(X),mean(X))))=>:ry])
2×3 DataFrame
Row │ x rx ry
│ Int64 Tuple… Tuple…
─────┼─────────────────────────────
1 │ 1 (1, 1) (3, 1.5)
2 │ 2 (2, 2) (203, 101.5)
I would like to ask where I can find examples of use of all the cases described here qui.
for cases where "standard column selectors (All
, Cols
, :
, Between
, Not
and regular expressions)
Also I would like to see some example for this case :
What is allowed for function
to return is determined by the target_cols
value:
- If both
cols
andtarget_cols
are omitted (so only afunction
is passed), then returning a data frame, a matrix, aNamedTuple
, or aDataFrameRow
will produce multiple columns in the result. Returning any other value produces a single column.