[R] How do I subtract sequential values ?

Joshua Wiley jwiley.psych at gmail.com
Mon Nov 29 05:09:34 CET 2010

On Sun, Nov 28, 2010 at 7:58 PM, Peter Ehlers <ehlers at ucalgary.ca> wrote:
> Then, since this is R, here's the next step:
>  v <- sample(50, 100, replace = TRUE)
>  result <- diff(v) / v[-length(v)]

Very nice!  It did not even occur to me to use diff() in this case,
though that is exactly what is needed and I've used it a hundred times
in other situations (I hope I'm like wine and get better with age


> Peter Ehlers

More information about the R-help mailing list