Inflation adjusted prices package?

inflation calculator
how to adjust for inflation in excel
how to adjust price data for inflation
inflation-adjusted housing prices 2019
consumer price index
inflation adjustment factor
how to adjust for cpi
how to compensate for inflation

Say I've got a data.frame with prices in one column and years in another:

prices <- rnorm(200, mean=10, sd=3)
years <- round(rnorm(200, mean=2006, sd=5))
df <- data.frame(prices, years)

Now say I want to normalize all these prices to 2008 dollars using the consumer price index. I could go look the conversion values up and do the calculation manually, but my intuition tells me that there is probably a package to do this automagically. A search of r-seek and cran did not yield anything obvious.

Does anyone know of anything?

You can get CPI data from FRED using the FRED method of the getSymbols function in the quantmod package

getSymbols("CPIAUCSL", src='FRED') #Consumer Price Index for All Urban Consumers: All Items
#           CPIAUCSL
#2012-03-01  229.098
#2012-04-01  229.177
#2012-05-01  228.527
#2012-06-01  228.618
#2012-07-01  228.723
#2012-08-01  230.102

# make an `xts` object of prices
p <- xts(rnorm(63, mean=10, sd=3), seq(from=as.Date('1950-12-01'), by='years', length.out=63))
colnames(p) <- "price"

The CPI inflation calculator at the BLS

... uses the average Consumer Price Index for a given calendar year... For the current year, the latest monthly index value is used.

(For this answer, I'm going to ignore the second part of the above quote...)

So, calculate an annual average

avg.cpi <- apply.yearly(CPIAUCSL, mean)

Then divide all index levels by the base price to create a conversion factor

cf <- avg.cpi/as.numeric(avg.cpi['2008']) #using 2008 as the base year
dat <- merge(p, cf, all=FALSE)
dat$adj <- dat[, 1] * dat[, 2]

#               price  CPIAUCSL       adj
#2006-12-01  8.898336 0.9363693  8.332128
#2007-12-01  6.867596 0.9632483  6.615200
#2008-12-01 11.709159 1.0000000 11.709159
#2009-12-01  9.594836 0.9967933  9.564069
#2010-12-01 17.204853 1.0131453 17.431015
#2011-12-01  9.882280 1.0449769 10.326754

Adjusting Prices for Inflation, observed in the market) by the CPI of that month, where the CPI is expressed as a ratio and not a percentage. In other words, a CPI of 150 is expressed as 1.5. Increased productivity in crop production underlies a general decrease in inflation-adjusted prices for corn, wheat, and soybeans over the past century. This downward price trend was reversed during the past decade by global growth in population and income, increasing biofuel production, and a depreciation of the U.S. dollar, but is likely to resume from these recent higher levels as

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 <-
             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.


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("", 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]

What is the meaning of "when adjusted for inflation?", we are comparing to things in the same prices. The most common approach is to use a base year Inflation-Adjusted Return: The inflation-adjusted return is the measure of return that takes into account the time period's inflation rate. Inflation-adjusted return reveals the return on an

The Importance Of Inflation And GDP, is increasing, people will spend more money because they know that it will be less valuable in the future. This causes further increases in GDP in the short term, bringing about further price increases. When you also factor in inflation, the price per square foot has remained pretty stable. Look at the price per square foot (inflation-adjusted) for new homes in the graph below. In 2017 the price per square foot of a new home was only 4% more (about $3) than in 1979. Which no longer sounds like much of a real estate bubble.

I think it should be noted that GSee's solution is technically correct but probably isn't want most people want when they talk about adjusting for inflation.

In my experience most people want to know how much an item purchased in years past would cost in today's dollars.

Based on GSee's code, this yields:

dat <- merge(p, cf, all=FALSE)
dat$adj <- dat[, 1] * dat[, 2]

Measuring Inflation Accurately, . Americans did not worry about “income stagnation” until the Great Recession—because it was not a widespread problem until then. The table below shows average annual prices of gasoline (all types) and those prices adjusted for inflation in 2017 dollars. It gives insights into how prices at the pump have changed over the years and how those prices compare when adjusted for inflation. Inflation Adjust Gasoline Prices (1978-2017)

BLS API Inflation and Prices, The CPI data tracks the prices paid by urban consumers for a representative basket of goods and services. The CPI is the primary metric used to calculate inflation. Getting these data from the blscrapeR package is easy enough: Note: the BLS recommends using non-seasonally adjusted data for  The inflation-adjusted price (aka. the price in “real dollars”) is how much you would have to pay back then, using the weakened purchasing power of today’s dollar. So if overall prices have doubled in the last ten years it would take two inflation-adjusted dollars to buy something that only cost one dollar, ten years ago.

Inflation adjustment of data for regression and forecasting, Inflation adjustment, or "deflation", is accomplished by dividing a monetary time series by a price index, such as the Consumer Price Index (CPI). By adjusting for inflation, you uncover the real growth, if any. This Chart presents Monthly Average Crude Oil Price and Inflation Adjusted Crude Oil Prices in chart form. The red line on the chart below shows oil prices adjusted for inflation in March 2015 dollars. The black line indicates the nominal price (in other words the price you would have actually paid for a barrel of oil at the time).

CPI Inflation Calculator, The CPI inflation calculator uses the Consumer Price Index for All Urban Consumers (CPI-U) U.S. city average series for all items, not seasonally adjusted​. The US Inflation Calculator uses the latest US government CPI data published on June 10, 2020 to adjust for inflation and calculate the cumulative inflation rate through May 2020. The U.S. Labor Department's Bureau of Labor Statistics will release the Consumer Price Index (CPI) with inflation data for June on July 14, 2020.

  • You can use getSymbols from quantmod 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
  • @GSee why a comment and not an answer? This seems pretty complete.
  • Nicely done. Going out and manually fetching the CPI was exactly what I was trying to do more intelligently.
  • @Peter, you're going to love quantmod. You also might like qmao
  • I might be completely crazy but don't you want to divide by the conversion factor? 2006 dollars are worth more in 2008 rather than less and 2011 dollars should be worth more right?
  • @AdamMccurdy If dollars are worth more, that means prices are lower; you can buy more goods with the same amount of dollars, so the price must be lower.
  • @GSee of course, I was pretty sure that I had missed something obvious. I was stuck thinking about the value of dollars not of prices. Thanks for addressing a silly question.
  • Did you know there's a CSV version?
  • Nice! this is simple and works without adding a bunch of tidyverse dependencies or translating to ts objects.