Skip to content

Commit

Permalink
compare stack/unstack to data.table melt/dcast (#3478)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock authored Nov 21, 2024
1 parent c27a231 commit 78f937b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/man/comparisons.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ df2 <- data.table(grp=c(1,3), w = c(10,11))
| | `df[, argmax_xy := which.max(.SD) , .SDcols = patterns("*x"), by = 1:nrow(df) ]` | `transform!(df, AsTable(r"^x") => ByRow(argmax))` |
| DataFrame as output | `df[, .SD[1], by=grp]` | `combine(groupby(df, :grp), first)` |
| DataFrame as output | `df[, .SD[which.max(x)], by=grp]` | `combine(groupby(df, :grp), sdf -> sdf[argmax(sdf.x), :])` |
| Reshape longer | `longdf = melt(df, measure.vars=c("x","y"), id.vars="id")` | `longdf = stack(df, [:x, :y], :id)` |
| Reshape wider | `dcast(longdf, id ~ variable, value.var="value")` | `unstack(longdf, :id, :variable, :value)`

### Joining data frames

Expand Down

0 comments on commit 78f937b

Please sign in to comment.