How can we take the difference between the values on yearly basis ?
Please find the reprex below with an attempt to solve &
library(tidyverse)
input = tribble(
~type,~val, ~year,
"digital",10, 2000,
"digital",20, 2001,
"digital",30, 2002,
"digital",15, 2003,
"manual",50, 2000,
"manual",25, 2001,
"manual",100, 2002,
"manual",50, 2003
)
# Basically relative growth on yearly basis for each combination
output <- tribble(
~type,~rel_val_per, ~year,
"digital",100, 2001,
"digital",100, 2002,
"digital",50, 2003,
"manual",50, 2000,
"manual",25, 2001,
"manual",100, 2002,
"manual",50, 2003
)
# tried
#
# x %>%
# gather(-type, key = key, value = val) %>%
# group_by(type) %>%
# mutate(relval = diff(val))