Sorry, I am stuck a bitβ¦: Suppose I have a function that takes Vectors and returns a DataFrame of the same length as the Vectors (e.g. my calc function below).
Then I can use => AsTable to get the names of the calculated DataFrame as new columns names. How can I programmatically add a suffix, to distinguish repeated calculations. I came up with
d = DataFrame(x1=rand(100), x2=rand(100))
#transform(d, [:x1, :x2] => ((x,y) -> calc(x,y)) => AsTable) # Standard way
#transform(d, [:x1, :x2] => ((x,y) -> calc(x,y)) => ["y1","y2","y3"] .* "_mycalc") # manually
transform(d, [:x1, :x2] => ((x,y) -> calc(x,y)) => names(calc(rand(2), rand(2))) .* "_mycalc") # The result I want
This is rather a workaround (dummy-calling the function)β¦ Is there a better way to access the names?
I donβt manage to do this at all with DataFrameMacros which I do like very much.
Currently the output column names are computed dynamically only if you use AsTable as target. In other cases they are computed statically (i.e. before the transformation function is called). So currently the only way to do it would be to define calc differently. Eg. like this:
Thanks, but that would not programmatically allow to add the suffix. Otherwise, a good βdesignβ question. I thought I wanted to stay within the well-defined DataFrame API framework. But I am happy about suggestions.
The use case is running dynamic models with several states forced by variables in a DataFrame.
Which is what βweβ do aboveβ¦ But your solution does not allow the programmatic addition of the suffix. Thatβs why @bkamins and I had solutions with suffix as function parameter.
but how AsTable works here cannot be modified due to the aforementioned limitations in the dispatch structure of the mini language. This is not something where DataFrameMacros could add convenience on top.