Skip to content
Prev 359060 / 398502 Next

difference between successive values

"Keep the first values" is imprecise, but mixing an absolute value with a bunch of differences doesn't usually work out well.  I frequently choose among

x <- sample( 10 )
dxright <- c( 0, diff(x) )
dxleft <- c( diff(x), 0 )

for calculation purposes depending on my needs.