Hello, I am a Julia newbie and I have a question.
The example below sort of simplified my current problemβ
function myfun(id)
a = [id .+ 1, id .+ 2, id .+ 2]
b = [id .- 1, id .- 2, id .- 3]
return [a, b]
end
mydf = DataFrame(id = [7, 8])
combine(groupby(mydf, :id), :id => myfun)
For each group (groupby id
in my data mydf
), I run a function, myfun
, which generates two arrays based on a variable in mydf
.
What I want to do is to add the two arrays (a
and b
) from the function to the original data as two columns.
However⦠the command below generates only a single column
combine(groupby(mydf, :id), :id => myfun)
4Γ2 DataFrame
Row β id id_myfun
β Int64 Arrayβ¦
ββββββΌββββββββββββββββββββββββββ
1 β 7 [[8], [9], [9]]
2 β 7 [[6], [5], [4]]
3 β 8 [[9], [10], [10]]
4 β 8 [[7], [6], [5]]
Ideally, I want my result to be like belowβ¦
Row β id β a βb
β Int64 β Int64 β Int64
ββββββΌββββββββββββββββββββββββββ
1 β 7 | 8 β 6
2 β 7 | 9 β 5
3 β 7 | 9 β 4
4 β 7 | 9 β 7
5 β 7 | 10 β 6
6 β 7 | 10 β 5
Is there anyone who could help me?
Thanks!