我想使用dbplyr
/dplyr
创建一个组级聚合变量。这是命令的要点:
q = tbl_copy %>%
group_by(group_var) %>%
mutate(x_agg = min(x))
但这会产生以下错误:
Error: Window function `min()` is not supported by this database
奇怪的是,当我使用summarise()
动词时,min()
效果很好。
q = tbl_copy %>%
group_by(group_var) %>%
summarise(x_agg = min(x))
q %>% show_query()
<SQL>
SELECT `group_var`, `x`, MIN(`x`) AS `x_agg`
FROM `my_table`
GROUP BY `group_var`
我错过了什么?如何在 MySQL 表的副本上使用group_by()
with ?mutate()
更新:一个可重现的例子
> con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
> copy_to(con, mtcars)
>
> mtcars2 <- tbl(con, "mtcars")
> mtcars2 %>%
+ select(mpg,cyl) %>%
+ group_by(cyl) %>%
+ mutate(mpg_min = min(mpg))
Error: Window function `min()` is not supported by this database