Skip to contents

Creates a First aggregation that computes the first value of each column in cols for each aggregation group.

Arguments

cols

String or list of strings denoting the column(s) to aggregate. Can be renaming expressions, i.e. “new_col = col”. Default is to aggregate all non-grouping columns, which is only valid in the agg_all_by() operation.

Value

AggOp to be used in a call to agg_by() or agg_all_by().

Details

The aggregation groups that this function acts on are defined with the by parameter of the agg_by() or agg_all_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").

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)

# get first elements of all columns
th1 <- th$
  agg_by(agg_first(c("X", "Y", "Number1", "Number2")))

# get first elements of Y, Number1, and Number2 grouped by X
th2 <- th$
  agg_by(agg_first(c("Y", "Number1", "Number2")), by = "X")

# get first elements of Number1 and Number2 grouped by X and Y
th3 <- th
agg_by(agg_first(c("Number1", "Number2")), by = c("X", "Y"))

client$close()
} # }