-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.Rmd
96 lines (75 loc) · 3.1 KB
/
README.Rmd
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>
[![Travis-CI Build Status](https://api.travis-ci.com/y-bar/mmetrics.svg?branch=master)](https://travis-ci.com/y-bar/mmetrics)
[![Build status](https://ci.appveyor.com/api/projects/status/99up72xw1eoj8s3i/branch/master?svg=true)](https://ci.appveyor.com/project/teramonagi/mmetrics/branch/master)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/mmetrics)](https://cran.r-project.org/package=mmetrics)
[![codecov](https://codecov.io/github/y-bar/mmetrics/branch/master/graphs/badge.svg)](https://codecov.io/github/y-bar/mmetrics)
[![Licence](https://img.shields.io/cran/l/mmetrics.svg)](https://github.com/y-bar/mmetrics/blob/master/LICENSE)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](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)