Scale relative to a value in each group (via dplyr)

后端 未结 3 528
抹茶落季
抹茶落季 2020-12-30 09:21

I have a set of time series, and I want to scale each of them relative to their value in a specific interval. That way, each series will be at 1.0 at that time and change pr

3条回答
  •  渐次进展
    2020-12-30 09:41

    Use first in dplyr, ensuring you use order_by

    data %>% 
      group_by(category) %>% 
      mutate(value = value / first(value, order_by = year))
    

提交回复
热议问题