I want to transform column x1 and x2 in df by apply each fun in xfun for the corresponding row of x1 and x2, I could use [:x1,:xfun]=>ByRow((x,f)->f(x))=>:x1, but what if there are 20 of these columns, is there other elegant way to achieve this?
The other way i can think of is to convert the columns to a Matrix, and broadcasting a vector of anonymous functions to the first dimention of the Matrix, but i donβt know if there is a generic apply function to broadcast?
transform keeps all source columns always; combine only keeps columns specified in transformations;
transform requires output to have as many rows as input; combine allows any number of rows in output.
Other than that these functions interpret transformation specifications in the same way (i.e. the same engine processes both requests, but different additional constraints are added)
but above all to ask for information on the use of the first function instead of a list of names / symbols of columns in output.
PS
I wonder if and when it will also be possible to write something like this
combine(df, [cols;"xfun"]=>ByRow((x...,f)->f.(x))=>cols)
# so for the given df is possible to save some typing :-)
combine(df, 2:4=>ByRow((x...,f)->f.(x))=>2:3)
I take this opportunity to ask you a further question, this one more specific one relating to the mini language.
If I understand correctly, some input forms such as columns range are not allowed in output.
For example 2: 3 => fun => 2: 3, it doesnβt work.
If so, what is the reason for these restrictions?
pass contents of columns 2 and 3 as positional arguments to function fun and expand the result returned by it into two columns whose names are taken as names of columns 2 and 3 from the source
The first question is if this is what you would expect. If this is what you would expect, at least for me this is a very specific case that is needed quite rarely and currently it can be expressed as 2:3 => fun => names(df, 2:3) which is only a bit more verbose.
For single column transformations like 2 => fun => 2 in your proposed notation, which are more common, either pass renamecols=false as kwarg and write just 2 => fun or write 2 => fun => identity to retain source column name. This does not cover the case like 2 => fun => 3, but again I think that it is quite rare.
What is your use case where you require this kind of transformations?