Re: [R] Multiple Lags with Dplyr

2019-04-23 Thread Gabor Grothendieck
lag.zoo supports vector-based lags on zoo objects. A few caveats: - dplyr's lag clobbers the base R lag (which you need to invoke lag's methods) so if you have dplyr loaded be sure to refer to stats::lag. - dplyr's lag works backwards relative to the standard set in base R so dplyr::lag(x, 1) cor

[R] Multiple Lags with Dplyr

2019-04-23 Thread Lorenzo Isella
Dear All, I refer to the excellent post at https://purrple.cat/blog/2018/03/02/multiple-lags-with-tidy-evaluation/ What I want to do is to create a function capable, à la dplyr, to generate new columns which are a lagged version of existing columns in a data frame. For instance, you can do this

[R] Multiple Lags with Dplyr

2019-04-23 Thread Lorenzo Isella
Dear All, I refer to the excellent post at https://purrple.cat/blog/2018/03/02/multiple-lags-with-tidy-evaluation/ What I want to do is to create a function capable, à la dplyr, to generate new columns which are a lagged version of existing columns in a data frame. For instance, you can do this