You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In R's tidyverse, the unnest_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 a DataFrame named test and see how we'd like the result to appear:
test =DataFrame(a = [1,2], b = [["c","d"],["e", "f"]])
# result
result =DataFrame(a = [1,2], b_1 = ["c" , "e"], b_2 = ["d", "f"])
To achieve a similar result in Julia using the DataFrames.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 the DataFrames minilanguage:
julia> test =DataFrame(a = [1,2], b = [["c","d"],["e", "f"]])
julia>functionsplit_uniformly(v)
n =length(first(v))
[NamedTuple(Symbol.("b", 1:n) .=>Tuple(amem))
for amem in v]
end
julia> test_wide =@chain test begintransform(:b=> split_uniformly => AsTable)
select(Not(:b))
end2×3 DataFrame
Row │ a b1 b2
│ Int64 String String
─────┼───────────────────────
1 │ 1 c d
2 │ 2 e f
The text was updated successfully, but these errors were encountered:
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:The text was updated successfully, but these errors were encountered: