add() is wrapper function of gmutate() and gsummarize(). gmutate() adds aggregated metrics as variables to the given data frame. gsummarize() aggregates metrics from the given data frame. gsummarize() and gsummarise() are synonyms. measure() and add() are also synonyms.

add(df, ..., metrics, summarize = TRUE, is_filtered = TRUE)

measure(df, ..., metrics, summarize = TRUE, is_filtered = TRUE)

gsummarize(df, ..., metrics, is_filtered = TRUE)

gsummarise(df, ..., metrics, is_filtered = TRUE)

gmutate(df, ..., metrics, is_filtered = TRUE)

Arguments

df

Data frame.

...

Variables to group by.

metrics

Metrics defined by mmetrics::define().

summarize

Summarization flag. If it is TRUE, add() works as gsummarize(). Otherwise, add() works as gmutate().

is_filtered

Filter metrics which does not work for df or not

Value

Data frame with calculated metrics

Examples

# Prepare data frame df <- data.frame( gender = rep(c("M", "F"), 5), age = (1:10)*10, cost = (51:60), impression = (101:110), click = (0:9)*3 ) # Define metrics metrics <- mmetrics::define( count = n(), cost = sum(cost), ctr = sum(click)/sum(impression) ) # Evaluate mmetrics::add(df, gender, metrics = metrics)
#> # A tibble: 2 x 4 #> gender count cost ctr #> <fct> <int> <int> <dbl> #> 1 F 5 280 0.142 #> 2 M 5 275 0.114