From 78f937be1facd67a2ae306e8b3338be189e311cb Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Thu, 21 Nov 2024 04:08:02 -0500 Subject: [PATCH] compare stack/unstack to data.table melt/dcast (#3478) --- docs/src/man/comparisons.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/man/comparisons.md b/docs/src/man/comparisons.md index 369395bdb..f499abade 100644 --- a/docs/src/man/comparisons.md +++ b/docs/src/man/comparisons.md @@ -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