Skip to content

Commit 78f937b

Browse files
authored
compare stack/unstack to data.table melt/dcast (#3478)
1 parent c27a231 commit 78f937b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/src/man/comparisons.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ df2 <- data.table(grp=c(1,3), w = c(10,11))
291291
| | `df[, argmax_xy := which.max(.SD) , .SDcols = patterns("*x"), by = 1:nrow(df) ]` | `transform!(df, AsTable(r"^x") => ByRow(argmax))` |
292292
| DataFrame as output | `df[, .SD[1], by=grp]` | `combine(groupby(df, :grp), first)` |
293293
| DataFrame as output | `df[, .SD[which.max(x)], by=grp]` | `combine(groupby(df, :grp), sdf -> sdf[argmax(sdf.x), :])` |
294+
| Reshape longer | `longdf = melt(df, measure.vars=c("x","y"), id.vars="id")` | `longdf = stack(df, [:x, :y], :id)` |
295+
| Reshape wider | `dcast(longdf, id ~ variable, value.var="value")` | `unstack(longdf, :id, :variable, :value)`
294296

295297
### Joining data frames
296298

0 commit comments

Comments
 (0)