excess <- excess %>% rename(Supply = Count.x, Demand = Count.y) %>% mutate(Excess = ifelse(!is.na(lag(Excess_per_month)), Excess_per_month + lag(Excess), Excess_per_month))
I tried to calculate Excess from the previous cell, lag doesnt work.
This is in an R shiny framework, where I add excel file to calculate some stuff.
lag(Excess_per_month) doesn't work since it only lags for the previous month, not the months before.
Basically what is needed is Excess = Excess_per_month + lag(Excess)