[R] seeking help with splicing in R

Manya Budhiraja mbudh|r@j@ @end|ng |rom um@@@@edu
Wed Apr 10 21:16:12 CEST 2024


I was trying to splice two wholesale price index deflators series which
have different base years. One of them is called wpi_def_nic2004(from 2005
to 2012), and another is called wpi_def_nic2008(from 2012 to 2019). I am
trying to create a single series such that the base year prices are
consistent with wpi_def_nic2008. The common year is 2012, which is used for
starting the splicing.

I would like to keep the values in the nic2008 series unchanged. The
nic2004 starts in 2005, and I would like to make the nic2004 series
consistent with nic2008. Moreover, I need to do this for each 2 digit
industry. I tried the following code, *but the problem I encounter is that
R only splices the nic2004 series only for the year 2011.* It does not
understand from my code that it can use the spliced value of 2011 in the
nic2004 series to go further back in the nic2004 series to splice the
remaining values from 2005-2011. This is the code I am using:

 merged <- full_join(wpi_def_nic2004,wpi_def_nic2008)

merged <- merged |> group_by(IND_CD_2D) |>
  mutate(spliced = case_when(year >= 2012 ~ def_value_nic2008,
                             year <= 2011 ~


Thanks a lot!

	[[alternative HTML version deleted]]

More information about the R-help mailing list