mmetrics (version 0.3.0)

add: Aggregate metrics

Description

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.

Usage

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

gsummarize(df, ..., metrics)

gsummarise(df, ..., metrics)

gmutate(df, ..., metrics)

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().

Value

Data frame with calculated metrics

Examples

Run this code
# NOT RUN {
# 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(
  cost = sum(cost),
  ctr  = sum(click)/sum(impression)
)

# Evaluate
mmetrics::add(df, gender, metrics = metrics)

# }

Run the code above in your browser using DataCamp Workspace