0

Can someone please help me to convert the "new value " calculation from excel to R:

new value (week 1) = original value (week 1),
new value (week 2) = original value (week 2) + new value (week 1) * multiplier (week 1),
new value (week 3) = original value (week 3) + new value (week 2) * multiplier (week 2),
new value (week n) = original value (week n) + new value (week (n-1)) * multiplier (week (n-1))

data

I have tried the following:

Code

Martin Gal
  • 16,640
  • 5
  • 21
  • 39
  • 1
    Have a look at `dplyr::lag` and `dplyr::lead`. I think you want `df %>% mutate(new_value = original_value + lag(original_value) * lag(multiplier))` – Axeman Apr 12 '22 at 18:07
  • Hi there and welcome to SO. Please make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) or [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with a sample input (not posted in an image, consider using `dput()`) and your expected output. So we can understand your problem and think about a possible solution and verify it compared to your expected output. Usually you have to show some effort (i.e. code you wrote by yourself) and then ask a question about the issues you encountered. – Martin Gal Apr 12 '22 at 18:50

0 Answers0