Closed atantos closed 9 months ago
Love the suggestion!
Also, just to check, flatten()
is the equivalent of unnest_longer()
, right?
https://dataframes.juliadata.org/stable/lib/functions/#DataFrames.flatten
julia> df1 = DataFrame(a=[1, 2], b=[[1, 2], [3, 4]], c=[[5, 6], [7, 8]])
2×3 DataFrame
Row │ a b c
│ Int64 Array… Array…
─────┼───────────────────────
1 │ 1 [1, 2] [5, 6]
2 │ 2 [3, 4] [7, 8]
julia> flatten(df1, :b)
4×3 DataFrame
Row │ a b c
│ Int64 Int64 Array…
─────┼──────────────────────
1 │ 1 1 [5, 6]
2 │ 1 2 [5, 6]
3 │ 2 3 [7, 8]
4 │ 2 4 [7, 8]
Exactly! flatten()
is the equivalent. However, I guess there are some decisions to be made over here..either keep flatten()
and a new function with a similar name (but without unnest in front) that corresponds to R's unnest_wider()
or for consistency with the tidyverse idea reshape flatten()
a bit and name it unnest_longer()
, while you also create a unnest_wider()
.
@nest()
, @unnest_longer()
, and @unnest_wider()
are now officially supported in v0.14.4.
Hey there!
In
R
'stidyverse
, theunnest_wider()
function provides a convenient way to spread the contents of a column, which contains arrays or lists of values, across multiple new columns. Let's consider aDataFrame
namedtest
and see how we'd like the result to appear:To achieve that with
R
'stidyverse
we would have:To achieve a similar result in
Julia
using theDataFrames.jl
package, the process is straightforward, albeit with a distinct Julia-idiomatic flavor. First, we'd define a function,split_uniformly()
, to handle the transformation. Then, we'd use this function within the transformation pipeline provided by theDataFrames
minilanguage: