Beginning with this dataset:
df <- data.frame(
year = 2007,
month = c('Jan', 'Feb', 'Mar', 'April'),
percent_change = c(0.0314, 0.0073, 0.0135, -0.0144),
to_multiply = c(1.0314, 1.0073, 1.0135, .9856)
)
I would like to produce the following dataset.
year month percent_change to_multiply dollar_value
2007 Jan 0.0314 1.0314 103.1400
2007 Feb 0.0073 1.0073 103.8929
2007 Mar 0.0135 1.0135 105.2955
2007 April -0.0144 0.9856 103.7792
I am wondering how to programmatically assign an initial value and create a new column displaying the value of a stock after each month. This is easy to do in a spreadsheet, but I'd like to stay away from that so I can rapidly chart different start dates and/or allocations using the same initial start value.
I have tried mutate with a lag wrapper, but I couldn't get that to work. I looked at RCCPRoll, but also couldn't make that work.