0

I have to calculate the inflation rate from 1990-2010. I have to do this with the CPI, which I have for each month for the 20 years. This means that I have to calculate the percentage growth rate for the same month of the previous year.

My teacher gave me this code:

n <- length(cpi)
infl <- cpi[13:n]/cpi[1:(n-12)]

Can somebody explain me the code and how I can use it?

my data

camille
  • 16,432
  • 18
  • 38
  • 60
Karrob
  • 1
  • 2
  • `cpi` seems like a vector with length `n`. The code says divide all values from where the index of `cpi` is 13 or more and divide it by the first year if it is sorted correctly. – akash87 Jan 14 '20 at 20:54
  • It's hard to know exactly without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)β€”it's unclear how that Excel table relates to your code, and we can't run code on a picture of a spreadsheet either way – camille Jan 14 '20 at 21:22

0 Answers0