inst/doc/Inflation_and_Prices.R

## ----setup, include=TRUE------------------------------------------------------

## ----eval=FALSE---------------------------------------------------------------
#  library(blscrapeR)
#  df <- bls_api("CUSR0000SA0")
#  head(df)

## ----eval=FALSE---------------------------------------------------------------
#  df <- inflation_adjust("2015-01-01") %>%
#      arrange(desc(date))
#  head(df)

## ----eval=FALSE---------------------------------------------------------------
#  library(blscrapeR)
#  df <- bls_api("CUSR0000SA0",
#                startyear = 2014, endyear = 2015)
#  head(df)
#  # Set base value.
#  base_value <- 100
#  # Get CPI from base period (January 2014).
#  base_cpi <- subset(df, year==2014 & periodName=="January", select = "value")
#  # Get the CPI for the new period (February 2015).
#  new_cpi <- subset(df, year==2015 & periodName=="February", select = "value")
#  # Calculate the updated value of our $100 investment.
#  (base_value / base_cpi) * new_cpi
#  # Woops, looks like we lost a penny!

Try the blscrapeR package in your browser

Any scripts or data that you put into this service are public.

blscrapeR documentation built on May 29, 2024, 1:34 a.m.