-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME.Rmd
More file actions
96 lines (75 loc) · 3.1 KB
/
Copy pathREADME.Rmd
File metadata and controls
96 lines (75 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
options(knitr.table.format = 'markdown')
```
# mmetrics <a href='https://y-bar.github.io/mmetrics/'><img src='man/figures/logo.png' align="right" height="139" /></a>
[](https://travis-ci.com/y-bar/mmetrics)
[](https://ci.appveyor.com/project/teramonagi/mmetrics/branch/master)
[](https://cran.r-project.org/package=mmetrics)
[](https://codecov.io/github/y-bar/mmetrics)
[](https://github.com/y-bar/mmetrics/blob/master/LICENSE)
[](https://www.tidyverse.org/lifecycle/#experimental)
Easy Computation of Marketing Metrics with Different Analysis Axis.
## Installation
You can install the released version of {mmetrics} from CRAN with:
```r
install.packages("mmetrics")
```
Or install the development version from github with:
```r
# install.packages("remotes")
remotes::install_github("y-bar/mmetrics")
```
## Example
### Load Dummy data
First, we load dummy data from {mmetrics} package for this example.
```{r}
df <- mmetrics::dummy_data
df
```
### Define metrics
As a next step, we define metrics to evaluate using `mmetrics::define`.
```{r}
# Example metrics
metrics <- mmetrics::define(
cost = sum(cost),
ctr = sum(click)/sum(impression) # CTR, Click Through Rate
)
```
### Just call `mmetrics::add()` !
Call `mmetrics::add()` with grouping key (here `gender`) then we will get new `data.frame` with defined metrics.
```{r}
mmetrics::add(df, gender, metrics = metrics)
```
### Remove aggregate function from metrics using `mmetrics::disaggregate()`
It is hassle for users to re-define metrics when you would like to use these for `dplyr::mutate()`.
In this case, you can use `mmetrics::disaggregate()` to remove *the first aggregation function* for the argument and return disaggregated metrics.
```{r}
# Original metrics. sum() is used for this metrics
metrics
```
```{r}
# Disaggregate metrics!
metrics_disaggregated <- mmetrics::disaggregate(metrics)
# Woo! sum() are removed!!!
metrics_disaggregated
```
You can use these metrics with `dplyr::mutate()` for row-wise metrics computation.
```{r}
dplyr::mutate(df, !!!metrics_disaggregated)
```
...or, you can do the same compucation using `mmetrics::gmutate()` defind in our package.
In this case, you do not need to write `!!!` (bang-bang-bang) operator explicitly.
```{r}
mmetrics::gmutate(df, metrics = metrics_disaggregated)
```
## More examples
- As a first step, see the vignettes [Introduction to {mmetrics} package](https://y-bar.github.io/mmetrics/articles/introduction.html)