add: Aggregate metrics

Description Usage Arguments Value Examples

View source: R/mmetrics.R

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

1
2
3
4
5
6
7
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 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)

mmetrics documentation built on July 26, 2019, 9:03 a.m.