| db_compute_count | R Documentation |
Uses dplyr operations to aggregate data. Because of this approach, the calculations automatically run inside the database if 'data' has a database or sparklyr connection. The 'class()' of such tables in R are: tbl_sql, tbl_dbi, tbl_spark
db_compute_count(data, x, ..., y = n())
data |
A table (tbl) |
x |
A discrete variable |
... |
A set of named or unnamed aggregations |
y |
The aggregation formula. Defaults to count (n) |
An ungrouped data.frame with the discrete variable and one or more aggregation columns. The first column is the grouping variable (x), followed by the aggregated values.
## Not run:
library(DBI)
library(dplyr)
con <- dbConnect(duckdb::duckdb(), ":memory:")
db_mtcars <- copy_to(con, mtcars, "mtcars")
# Returns the row count per am
db_mtcars |>
db_compute_count(am)
# Returns the average mpg per am
db_mtcars |>
db_compute_count(am, mean(mpg))
# Returns the average and sum of mpg per am
db_mtcars |>
db_compute_count(am, mean(mpg), sum(mpg))
dbDisconnect(con)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.