How does it work to aggregate a variable in a postgres db backend table to its unique value. For example i have the following table:
library(tidyverse)
library(dbplyr)
dbplyr::memdb_frame(a=c(2,2,2), b=c(2,3,4)) %>%
summarise(aggregatedSum = sum(b),
aggregatedUnique = unique(a))
But neither unique()
nor distinct()
are doing the job. Any ideas how to achieve my desired outcome like so when i collect() the table before summarise:
dbplyr::memdb_frame(a=c(2,2,2), b=c(2,3,4)) %>%
collect() %>%
summarise(aggregatedSum = sum(b),
aggregatedUnique = unique(a))
# A tibble: 1 x 2
aggregatedSum aggregatedUnique
<dbl> <dbl>
1 9 2