I am trying to keep the original data but calculate a lag only for certain rows of the text. Iv'e tried filtering but it leaves out the data. Also, the lag doesn't seem to really consider the dt..
What do you think?
library (tidyverse)
df2<- nycflights13::weather
df2 <- df2 %>% mutate (dt= as.Date(time_hour)) %>% add_count(origin,dt)
df2 <- df2 %>% mutate(lag_ewr1=lag(n,1))