Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/y-bar/mmetrics

Easy computation of Marketing Metrics in R
https://github.com/y-bar/mmetrics

marketing marketing-analytics marketing-tools r

Last synced: 3 months ago
JSON representation

Easy computation of Marketing Metrics in R

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
options(knitr.table.format = 'markdown')
```

# mmetrics

[![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)