-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create an efficient unnest function #2146
Comments
Also: https://stackoverflow.com/questions/44336733/ Suggestion to make such a function more flexible than
|
Some other possible extensions / convenience features from this SO q: https://stackoverflow.com/q/56981960
|
As a mod to @franknarf1 's code, the empty row can be preserved tidyr::unnest(DT, colB, keep_empty = TRUE)
# # A tibble: 5 x 5
# colA colsubB1 colsubB2 colC colD
# <chr> <chr> <chr> <chr> <chr>
# 1 A1 <NA> <NA> C1 D1
# 2 A2 B2a B2c C2 D2
# 3 A2 B2b B2d C2 D2
# 4 A3 A3a A3c C3 D3
# 5 A3 A3b A3d C3 D3 |
This seems to work quite efficiently (my test with 1 million rows of similar structure took about a minute) dt <- data.table(A=c(1,2,3),B=list(c("A","B","C"),"D",c("E","F"))
dt.flat <- dt[,unlist(B),by=A] |
For reference the unnest implementation in mlr3misc: https://mlr3misc.mlr-org.com/reference/unnest.html |
Similarly to
tidyr:::unnest
data.table
would benefits from a fast unnest function.I found
is there something canonical ?
if not that a FR !
The text was updated successfully, but these errors were encountered: