Suppose I have some function fun
that takes in multiple columns of a GroupedDataFrame and outputs a series of calculations with additional parameters. I would like to output these calculations to new columns of the GroupedDataFrame via transform so that it would look something like this.
transform!(GDF, [:A, :B ] => (a, b ) -> fun(a,b, p1,p2) => [:NewA, :NewB:, NewAB]
What type of output does fun
need to return so that the calculations may output to the newly named columns?
after reading bkamins very informative post on DataFrames minilanguage https://bkamins.github.io/julialang/2020/12/24/minilanguage.html
I tried tried having the function return a tuple
function fun(A,B, p1,p2)
...
return (NewA, NewB, NewAB)
named tuple
return NewCols = (A = NewA , B = NewB, AB = NewAB)
Vector
return [NewA, NewB, NewAB]
However the output always gets bunched together into an auto-named single column once it is used in transform!
When I tried returning a DataFrame
return NewCols = DataFrame(A = NewA , B = NewB, AB = NewAB)
The entire DataFrame was outputted to the newly generated column where each row of the newly generated column was a copy of the entire DataFrame.
I am not sure if my mistake is the format of what fun
is returning or if it is how I have the mini language written? Any pointers on where I am going wrong would be greatly appreciated! Thanks!