-
Notifications
You must be signed in to change notification settings - Fork 28
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
median
calculation fails when using dplyr::mutate
#993
Comments
Added a PR for translating median. You might also consider using duckplyr. For example: library(duckplyr)
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#> ✔ Overwriting dplyr methods with duckplyr methods.
#> ℹ Turn off with `duckplyr::methods_restore()`.
tbl_aq <- as_duck_tbl(airquality)
df <- tbl_aq |>
mutate(
.by = Day,
med = median(Temp)
)
df |> explain()
#> ┌───────────────────────────┐
#> │ PROJECTION │
#> │ ──────────────────── │
#> │ #0 │
#> │ #1 │
#> │ #2 │
#> │ #3 │
#> │ #4 │
#> │ #5 │
#> │ #6 │
#> │ │
#> │ ~153 Rows │
#> └─────────────┬─────────────┘
#> ┌─────────────┴─────────────┐
#> │ WINDOW │
#> │ ──────────────────── │
#> │ Projections: │
#> │ median(Temp) OVER │
#> │ (PARTITION BY Day) │
#> └─────────────┬─────────────┘
#> ┌─────────────┴─────────────┐
#> │ R_DATAFRAME_SCAN │
#> │ ──────────────────── │
#> │ Text: data.frame │
#> │ │
#> │ Projections: │
#> │ Ozone │
#> │ Solar.R │
#> │ Wind │
#> │ Temp │
#> │ Month │
#> │ Day │
#> │ │
#> │ ~153 Rows │
#> └───────────────────────────┘
df
#> # A duckplyr data frame: 7 variables
#> Ozone Solar.R Wind Temp Month Day med
#> <int> <int> <dbl> <int> <int> <int> <dbl>
#> 1 16 256 9.7 69 5 12 76
#> 2 12 149 12.6 74 5 3 81
#> 3 NA 242 16.1 67 6 3 81
#> 4 32 236 9.2 81 7 3 81
#> 5 16 77 7.4 82 8 3 81
#> 6 73 183 2.8 93 9 3 81
#> 7 28 NA 14.9 66 5 6 83
#> 8 NA 264 14.3 79 6 6 83
#> 9 40 314 10.9 83 7 6 83
#> 10 66 NA 4.6 87 8 6 83
#> # ℹ more rows Created on 2025-01-18 with reprex v2.1.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created on 2025-01-09 with reprex v2.1.1
Session info
It looks like there is a median function available. https://duckdb.org/docs/sql/functions/aggregates#medianx
Couldn't this be just used instead of
percentile_cont
?The text was updated successfully, but these errors were encountered: