I have a dataframe, or tibble, that I need to do some calculations across different observations & values. A simple example is in the df_old tibble below.
df_old <- tibble(
fwd_date= as.Date(c("2019-12-01", "2019-12-01", "2020-01-01", "2020-01-01")),
commodity=c("wti", "wcs", "wti", "wcs"),
price=c(50.00,-12.00, 55.00, -18.00))
I simply need to add the wti and wcs value for each fwd_date so that it looks like the df_new tibble below. I tried a variety of manipulations (lead, lag, mutate etc.), but I'm stuck.
df_new <- tibble(
fwd_date= as.Date(c("2019-12-01", "2020-01-01")),
commodity=c("combined", "combined"),
price=c(38, 37))
Any advice the r community can provide would be greatly appreciated.
Thanks in advance.
CJ