I would like to compute the weighted median of a variable on R.
Due to the size of my dataset, I need to use duckdb.
I did this :
library(nycflights13) #dataset example
library("Hmisc") # for the function wtd.quantile
con <- dbConnect(duckdb())
duckdb_register(con, "flights", nycflights13::flights)
colnames(flights)
tbl(con, "flights") %>%
summarise(.by = dest,
delay = median(dep_time, na.rm = T))
tbl(con, "flights") %>%
summarise(.by = dest,
wg.delay = wtd.quantile(dep_time, weights = distance, type = "quantile"))
I receive this error :
Error in
collect(): ! Failed to collect lazy table. Caused by error: ! Parser Error: syntax error at or near "AS" LINE 3: wtd.quantile(dep_time, distance AS weights, 'quantile' A...
Could anyone help me ?