I am having some trouble using a vectorized function and assigning the output to a DataFrames
row. Here is a simple MWE below. The function computes multiple values as the output, and I wanted to assign each element of the output to different rows of the dataframe. Instead, I am getting that the entire tuple of function outputs gets assigned to each column of the dataframe.
This should be a simple syntax thing, but I am missing it.
function myfunc(a, b)
return string(a+b), a, b
end
testdata = DataFrame(rand(5, 4), :auto)
testdata[!, 1] = ["one", "two", "three", "four", "five"]
testdata[!, 2:4] .= myfunc.(collect(1:5), collect(2:6))
But the output looks like this:
5Γ4 DataFrame
Row β x1 x2 x3 x4
β String Tupleβ¦ Tupleβ¦ Tupleβ¦
ββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββ
1 β one ("3", 1, 2) ("3", 1, 2) ("3", 1, 2)
2 β two ("5", 2, 3) ("5", 2, 3) ("5", 2, 3)
3 β three ("7", 3, 4) ("7", 3, 4) ("7", 3, 4)
4 β four ("9", 4, 5) ("9", 4, 5) ("9", 4, 5)
5 β five ("11", 5, 6) ("11", 5, 6) ("11", 5, 6)
I actually want the output to look like this:
5Γ4 DataFrame
Row β x1 x2 x3 x4
β String Tupleβ¦ Tupleβ¦ Tupleβ¦
ββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββ
1 β one "3" 1 2
2 β two "5" 2 3
3 β three "7" 3 4
4 β four "9" 4 5
5 β five "11" 5 6
Thanks for any input.