How to find subtract the values corresponding to previous date from the next date in R

Viewed 37
1 Answers

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(.))))
Related