[R] lagging over consecutive pairs of rows in dataframe

Evan Cooch evan.cooch at gmail.com
Fri Mar 17 18:14:24 CET 2017



On 3/17/2017 12:58 PM, Ulrik Stervbo wrote:
> Hi Evan
>
> you can easily do this by applying diff() to each exp group.
>
> Either using dplyr:
> library(dplyr)
> mydata %>%
>   group_by(exp) %>%
>   summarise(difference = diff(rslt))
>
> Or with base R
> aggregate(mydata, by = list(group = mydata$exp), FUN = diff)
>
>


Indeed -- thanks very much!

	[[alternative HTML version deleted]]



More information about the R-help mailing list