I have some results for ab tests in a dataframe, recording the percentage of visitors with different events in different variants. For each variant combination of a test on a given date, I would like to know the change in the percentage of visitors with that event.
See below for a toy example; original_df is what I have, and I would like to get to desired result. I've tried widyr and tidyr in combination with dplyr, but nothing quite works.
library(tibble)
#> Warning: package 'tibble' was built under R version 3.4.1
original_df <- tribble(
~date, ~ab_test, ~ab_variant, ~event_name, ~perc_w_event,
"10-09-2017", "cool_test", "old", "clicks", .1,
"10-09-2017", "cool_test", "new", "clicks", .2,
"10-09-2017", "cool_test", "third_variant", "clicks", .5,
"10-09-2017", "awesome_test", "off", "clicks", .3,
"10-09-2017", "awesome_test", "on", "clicks", .4,
"10-10-2017", "awesome_test", "off", "clicks", .6,
"10-10-2017", "awesome_test", "on", "clicks", .8
)
desired_result <- tribble(
~date, ~ab_test, ~variant_1, ~variant_2, ~event_name, ~perc_change,
"10-09-2017", "cool_test", "old", "new", "clicks", 100,
"10-09-2017", "cool_test", "old", "third_variant", "clicks", 400,
"10-09-2017", "cool_test", "new", "third_variant", "clicks", 150,
"10-09-2017", "awesome_test", "off", "on", "clicks", 33.33,
"10-10-2017", "awesome_test", "off", "on", "clicks", 33.33
)