[This article was first published on R Tricks – Data Science Riot!, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I was surprised to see there weren’t more of these types of calculators in the R community. Inflation and adjusted payments seem like they would be more common. I was able to find a way to gather Consumer Price Index data using the quantmod package but quantmod leaves you to your own devices in converting the data. So, I whipped up a formula, this will most likely be incorporated into my upcoming BLS scrape package.

The function grabs the CPI data as a flat file, converts the data to an xts object and finds the average CPI index for each year. It then calculates an adjusted “dollar” by dividing the average CPI for your target year to your base year and uses that multiplier to calculate the value of a dollar for any given year related to your base year.

Note: for this to work you must have a “base year,” i.e. something to compare to. So, if I wanted to know the current-day value of $1.00 USD from 1947, I would use 1947 for my base year and find out the 2015 value is$10.62.

The Results:

 date base.year adj_value pct_increase 12/1/10 1947 9.78 878.0269058 12/1/11 1947 10.09 908.5201794 12/1/12 1947 10.3 929.5964126 12/1/13 1947 10.45 944.8430493 12/1/14 1947 10.61 961.4349776 10/1/15 1947 10.62 961.8834081

To check the math, I can go to the BLS inflation calculator web-app.

The Code:

inflation_adjust

Photo by che1899