Search code examples
rvectormultiplicationsimulate

How to simulate a vector of growth rate data in R


Say I know the monthly growth rate is 5%, and I know that for January 2018 the base number is 1000. How do I create a vector that has a length of 12, which shows the total monthly numbers for the year 2018? So for example, the first four elements in the vector would be:

c(1000, 1000*1.05, 1000*1.05^2, 1000*1.05^3)

Is there a function that I can do this easily? I am thinking of using the rep() function somehow.


Solution

  • Try cumprod

    cumprod(c(1000, rep(1.05, 12)))
    
    [1] 1000.000 1050.000 1102.500 1157.625 1215.506 1276.282 1340.096
    [8] 1407.100 1477.455 1551.328 1628.895 1710.339 1795.856