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

mmetrics

Travis-CI Build Status Build status CRAN_Status_Badge codecov Licence Lifecycle: experimental

Easy Computation of Marketing Metrics with Different Analysis Axis.

Installation

You can install the released version of {mmetrics} from CRAN with:

install.packages("mmetrics")

Or install the development version from github with:

# install.packages("remotes")
remotes::install_github("y-bar/mmetrics")

Example

Load Dummy data

First, we load dummy data from {mmetrics} package for this example.

df <- mmetrics::dummy_data
df

Define metrics

As a next step, we define metrics to evaluate using mmetrics::define.

# 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.

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.

# Original metrics. sum() is used for this metrics
metrics
# 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.

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.

mmetrics::gmutate(df, metrics = metrics_disaggregated)

More examples



shinichi-takayanagi/mmetrics documentation built on Aug. 10, 2019, 6:31 p.m.