Adjust for inflation function

From MoxyWiki

This function converts Nominal Australian Dollars from one year into equivilant dollars in a different year using the Australian Consumer Price Index to account for the effects of inflation.

It allows us to answer questions such as:

 How much would 100 AUD in 1970 dollars be worth in 1981?

The function takes three arguments:

  1. The input value to be converted (in this example 100)
  2. The year in which the input value relates (1970)
  3. The target year (1981)

The function returns the value of the input expressed in target year dollars.

function(inputValue, fromYear, toYear){
#Step 1 load in the CPI data
cpi = sparql("SELECT ?x WHERE{<http://www.moxy.com.au/Wiki/a#Australian_Consumer_Price_Index> prop:RData ?x}");

#Average the CPI index data by year
cpi$Year = substr(cpi$Quarter, 5, 8);

# Summarise the data by year
cpiYear = tapply(cpi$Index, cpi$Year, mean);

#Convert from fromYear to base
targetVal = inputValue * cpiYear[as.character(toYear)] / cpiYear[as.character(fromYear)];
targetVal 
}
Facts about Adjust for inflation functionRDF feed
CurrencyAustralian Dollars  +
RScript
function(inputValue, fromYear, toYear){
#Step 1 load in the CPI data
cpi = sparql("SELECT ?x WHERE{<http://www.moxy.com.au/Wiki/a#Australian_Consumer_Price_Index> prop:RData ?x}");

#Average the CPI index data by year
cpi$Year = substr(cpi$Quarter, 5, 8);

# Summarise the data by year
cpiYear = tapply(cpi$Index, cpi$Year, mean);

#Convert from fromYear to base
targetVal = inputValue * cpiYear[as.character(toYear)] / cpiYear[as.character(fromYear)];
targetVal 
}