-1

I want to create a new variable called REF_YEARCPI that aggregates the CPIs for all 12 months within the year. In the table, there is a variable called REF_MONTHCPI but I need to transform this variable into an annual variable (called REF_YEARCPI) that aggregates 12 of the CPI values within the year. In the image, I have 2 columns: REF_MONTHCPI stores the monthly reference periods and CPI_RESTAURANT which stores the CPI for the month.

Community
  • 1
  • 1
  • 1
    Welcome to SO! Please, read [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to have better chances to get a good answer (and not downvotes and/or closed question). – s__ Oct 29 '18 at 14:59
  • Try `df1$REF_MONTHCPI-1) %/% 12 + 1` – akrun Oct 29 '18 at 15:02

1 Answers1

0

I don't know the name of the dataframe you have so I will assume it as df.

df$REF_YEARCPI <- df$REF_MONTHCPI * 12

You can replace df in the above code with the name of your dataframe.

KrSid
  • 50
  • 1
  • 8