This vignette shows you how to use {mmetrics}
package.
First, we create dummy data for this example.
# Dummy data
df <- data.frame(
gender = rep(c("M", "F"), 5),
age = (1:10)*10,
cost = c(51:60),
impression = c(101:110),
click = c(0:9)*3,
conversion = c(0:9)
)
head(df)
#> gender age cost impression click conversion
#> 1 M 10 51 101 0 0
#> 2 F 20 52 102 3 1
#> 3 M 30 53 103 6 2
#> 4 F 40 54 104 9 3
#> 5 M 50 55 105 12 4
#> 6 F 60 56 106 15 5
As a next step, we define metrics to evaluate using mmetrics::define
.
Call mmetrics::add()
with grouping key (here gender
) then we will get new data.frame
with defined metrics.
We can also use multiple grouping keys.
mmetrics::add(df, gender, age, metrics = metrics)
#> # A tibble: 10 x 4
#> gender age cost ctr
#> <fct> <dbl> <int> <dbl>
#> 1 F 20 52 0.0294
#> 2 F 40 54 0.0865
#> 3 F 60 56 0.142
#> 4 F 80 58 0.194
#> 5 F 100 60 0.245
#> 6 M 10 51 0
#> 7 M 30 53 0.0583
#> 8 M 50 55 0.114
#> 9 M 70 57 0.168
#> 10 M 90 59 0.220
Summarize all data when you do not specify any grouping keys.
When you set summarize = FALSE
, mmetrics::add()
behave like dplyr::mutate()
.
mmetrics::add(df, metrics = metrics, summarize = FALSE)
#> Warning in mmetrics::add(df, metrics = metrics, summarize = FALSE):
#> disaggregate() called inside. See the result of disaggregate(metrics) to
#> check wether output metrics is what you want.
#> # A tibble: 10 x 7
#> gender age cost impression click conversion ctr
#> <fct> <dbl> <int> <int> <dbl> <int> <dbl>
#> 1 M 10 51 101 0 0 0
#> 2 F 20 52 102 3 1 0.0294
#> 3 M 30 53 103 6 2 0.0583
#> 4 F 40 54 104 9 3 0.0865
#> 5 M 50 55 105 12 4 0.114
#> 6 F 60 56 106 15 5 0.142
#> 7 M 70 57 107 18 6 0.168
#> 8 F 80 58 108 21 7 0.194
#> 9 M 90 59 109 24 8 0.220
#> 10 F 100 60 110 27 9 0.245
In this situation, mmetrics::disaggregate()
is used inside to disaggregate metrics. See the result of disaggregate(metrics)
to check wether output metrics is what you want.