There is a much simpler solution for acquiring the annual CPI (e.g., CPIAUCSL) that does not require use of the quantmod
package, which seems to always have compatibility issues for one reason or another, at least in my experience.
require(lubridate) || install.packages("lubridate")
require(dplyr) || install.packages("dplyr")
monthly_cpi <-
read.table("http://research.stlouisfed.org/fred2/data/CPIAUCSL.txt",
skip = 53, header = TRUE)
monthly_cpi$cpi_year <- year(monthly_cpi$DATE)
yearly_cpi <- monthly_cpi %.% group_by(cpi_year) %.% summarize(cpi = mean(VALUE))
Then, to create your adjustment factor relative to say, last year's prices:
yearly_cpi$adj_factor <- yearly_cpi$cpi/yearly_cpi$cpi[yearly_cpi$cpi_year == 2013]
You have to find out how many lines to skip
, but then again, that causes you to actually look at the lines that are skipped by viewing the actual data source, which happens to have useful preamble information.
BUT WAIT! THERE'S MORE!
Thanks to @GSee (who gave the checked answer) for noting that there is a .csv
version for which you need not skip any rows! Using this version, the code is:
require(lubridate) || install.packages("lubridate")
require(dplyr) || install.packages("dplyr")
monthly_cpi <-
read.csv("http://research.stlouisfed.org/fred2/data/CPIAUCSL.csv", header = TRUE)
monthly_cpi$cpi_year <- year(monthly_cpi$DATE)
yearly_cpi <- monthly_cpi %.% group_by(cpi_year) %.% summarize(cpi = mean(VALUE))
yearly_cpi$adj_factor <- yearly_cpi$cpi/yearly_cpi$cpi[yearly_cpi$cpi_year == 2013]
getSymbols
fromquantmod
to download CPI data from FRED. I'm not sure which you want, but you can look here. e.g.getSymbols("CPIAUCSL", src='FRED')
will download the Consumer Price Index for All Urban Consumers: All Items