The data frame is arranged by date. I want to subtract the values on the previous date from the ones on the next date and display them.
The data frame is arranged by date. I want to subtract the values on the previous date from the ones on the next date and display them.
An option would be
library(dplyr)
df1 %>%
mutate_if(is.numeric, list( ~ . - lag(.)))
Or with diff
df1 %>%
mutate_if(is.numeric, list(~ c(NA, diff(.))))