[R] seeking help with splicing in R

Ebert,Timothy Aaron tebert @end|ng |rom u||@edu
Thu Apr 11 14:13:06 CEST 2024

Whatever you had as HTML was deleted. If that was data we did not get it.
1) manipulate wpi_def_nic2004 and wpi_def_nic2008 first so that the data are compatible, then join them.
2) The full_join statement should explicitly state the columns to join by. Using by=NULL joins by all the columns with the same name and that is risky. I might want to reuse code or I might change things and suddenly the code does not behave in the same way because I have used the default. That might be the answer: if both data frames have year as a common variable then they will be joined by year, but the years do not overlap. Look at your "merged" data frame carefully. Are you sure it is in the right format?
3) Are you sure you want a full_join, or do you want an inner_join where you get back only industries that are in both.
4) A stupid question: why not adjust the 2005-2012 data for inflation to "convert" base years?


-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Manya Budhiraja
Sent: Wednesday, April 10, 2024 3:16 PM
To: r-help using r-project.org
Subject: [R] seeking help with splicing in R

[External Email]


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

R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list