Number of observations by group
agg_count.RdCreates a Count aggregation that counts the number of rows in each aggregation group.
Value
AggOp to be used in a call to agg_by().
Details
The aggregation groups that this function acts on are defined with the by parameter of the agg_by() caller
function. The aggregation groups are defined by the unique combinations of values in the by columns. For example,
if by = c("A", "B"), then the aggregation groups are defined by the unique combinations of values in the A and
B columns.
This function, like other Deephaven agg functions, is a generator function. That is, its output is another
function called an AggOp intended to be used in a call to agg_by() or agg_all_by(). This detail is
typically hidden from the user. However, it is important to understand this detail for debugging purposes,
as the output of an agg function can otherwise seem unexpected.
For more information, see the vignette on agg functions by running
vignette("agg_by").
Note that this operation is not supported in agg_all_by().
Examples
if (FALSE) { # \dontrun{
library(rdeephaven)
# connecting to Deephaven server
client <- Client$new("localhost:10000", auth_type = "psk", auth_token = "my_secret_token")
# create data frame, push to server, retrieve TableHandle
df <- data.frame(
X = c("A", "B", "A", "C", "B", "A", "B", "B", "C"),
Y = c("M", "N", "O", "N", "P", "M", "O", "P", "M"),
Number1 = c(100, -44, 49, 11, -66, 50, 29, 18, -70),
Number2 = c(-55, 76, 20, 130, 230, -50, 73, 137, 214)
)
th <- client$import_table(df)
# count number of elements in each group when grouped by X, name resulting column "count"
th1 <- th$
agg_by(agg_count("count"), by = "X")
# count number of elements in each group when grouped by X and Y, name resulting column "CountingCol"
th2 <- th$
agg_by(agg_count("CountingCol"), by = c("X", "Y"))
client$close()
} # }