Working with multiple columns in DataFramesMeta, programmatically

For me it works correctly:

julia> transform(test, All() => ByRow((w,as...) -> sum((a-w)^2 for a ∈ as)) => :v)
3×5 DataFrame
 Row │ w      a1     a2     a3     v
     │ Int64  Int64  Int64  Int64  Int64
─────┼───────────────────────────────────
   1 │    10     12      9     14     21
   2 │    13      9     10     10     34
   3 │     5      6      8     12     59

(and it looks correct)

Maybe a more careful code would be e.g.

julia> transform(test, Cols(:w, r"a\d") => ByRow((w,as...) -> sum((a-w)^2 for a ∈ as)) => :v)
3×5 DataFrame
 Row │ w      a1     a2     a3     v
     │ Int64  Int64  Int64  Int64  Int64
─────┼───────────────────────────────────
   1 │    10     12      9     14     21
   2 │    13      9     10     10     34
   3 │     5      6      8     12     59

but it is a detail.

Regarding DataFramesMeta.jl - I think it is not possible currently there, but @pdeffebach is working on it.

On the other hand DataFrameMacros.jl should support this I think - @jules should know best.

1 Like