From fe635d98736d0e7d2949ca43993b80175de997b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Syver=20D=C3=B8ving=20Agdestein?= <40632532+agdestein@users.noreply.github.com> Date: Fri, 15 Nov 2024 22:34:06 +0100 Subject: [PATCH 1/4] docs: fix typo (#3474) --- docs/src/man/comparisons.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/man/comparisons.md b/docs/src/man/comparisons.md index f8405d106f..bf4adfa660 100644 --- a/docs/src/man/comparisons.md +++ b/docs/src/man/comparisons.md @@ -17,7 +17,7 @@ df2 = DataFrame(grp=[1, 3], w=[10, 11]) Some of the operations mutate the tables so every operation assumes that it is done on the original data frame. Note that in the comparisons presented below predicates like `x -> x >= 1` can -be more compactly written as `=>(1)`. The latter form has an additional benefit +be more compactly written as `>=(1)`. The latter form has an additional benefit that it is compiled only once per Julia session (as opposed to `x -> x >= 1` which defines a new anonymous function every time it is introduced). From 9e26a13ca9da2781fbed881887897003f5efe810 Mon Sep 17 00:00:00 2001 From: Rose Date: Thu, 21 Nov 2024 00:05:50 +1000 Subject: [PATCH 2/4] typo, df was d (#3477) --- src/groupeddataframe/groupeddataframe.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/groupeddataframe/groupeddataframe.jl b/src/groupeddataframe/groupeddataframe.jl index d08bef7f55..375994e62f 100644 --- a/src/groupeddataframe/groupeddataframe.jl +++ b/src/groupeddataframe/groupeddataframe.jl @@ -48,7 +48,7 @@ mutable struct GroupedDataFrame{T<:AbstractDataFrame} end """ - groupby(d::AbstractDataFrame, cols; + groupby(df::AbstractDataFrame, cols; sort::Union{Bool, Nothing, NamedTuple}=nothing, skipmissing::Bool=false) From c27a231ce3a2329648f0c2f31b3748fb246ed5d9 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Thu, 21 Nov 2024 04:05:35 -0500 Subject: [PATCH 3/4] dcast instead of SDcols (#3475) using dcast is simpler so you may consider mentioning that, for example below ```r > data.table(iris)[, unlist(lapply(.SD, function(x) c(max=max(x), min=min(x)))), .SDcols = c("Petal.Length", "Petal.Width") ] Petal.Length.max Petal.Length.min Petal.Width.max Petal.Width.min 6.9 1.0 2.5 0.1 > dcast(data.table(iris), . ~ ., list(max,min), value.var = c("Petal.Length", "Petal.Width")) Key: <.> . Petal.Length_max Petal.Width_max Petal.Length_min Petal.Width_min 1: . 6.9 2.5 1 0.1 ``` --- docs/src/man/comparisons.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/man/comparisons.md b/docs/src/man/comparisons.md index bf4adfa660..369395bdba 100644 --- a/docs/src/man/comparisons.md +++ b/docs/src/man/comparisons.md @@ -285,7 +285,7 @@ df2 <- data.table(grp=c(1,3), w = c(10,11)) | Transform several columns | `df[, .(max(x), min(y)) ]` | `combine(df, :x => maximum, :y => minimum)` | | | `df[, lapply(.SD, mean), .SDcols = c("x", "y") ]` | `combine(df, [:x, :y] .=> mean)` | | | `df[, lapply(.SD, mean), .SDcols = patterns("*x") ]` | `combine(df, names(df, r"^x") .=> mean)` | -| | `df[, unlist(lapply(.SD, function(x) c(max=max(x), min=min(x)))), .SDcols = c("x", "y") ]` | `combine(df, ([:x, :y] .=> [maximum minimum])...)` | +| | `dcast(df, . ~ ., list(max,min), value.var = c("x","y"))` | `combine(df, ([:x, :y] .=> [maximum minimum])...)` | | Multivariate function | `df[, .(cor(x,y)) ]` | `transform(df, [:x, :y] => cor)` | | Row-wise | `df[, min_xy := min(x, y), by = 1:nrow(df)]` | `transform!(df, [:x, :y] => ByRow(min))` | | | `df[, argmax_xy := which.max(.SD) , .SDcols = patterns("*x"), by = 1:nrow(df) ]` | `transform!(df, AsTable(r"^x") => ByRow(argmax))` | From 78f937be1facd67a2ae306e8b3338be189e311cb Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Thu, 21 Nov 2024 04:08:02 -0500 Subject: [PATCH 4/4] 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 369395bdba..f499abade9 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