Calculates differences between subsequent (or lagged) elements of a vector.
Very similar to
diff, but written in C++.
Numeric value (e.g. 2 for differences between 1st and 3rd element, 2nd and 4th, ...).
1 2 3 4 5 6 7 8 9 10 11 12
# Generate 1 million values from Poisson(3) distribution x <- rpois(100000, 3) # Calculate vector of differences between subsequent values y <- diffs(x) # Could get same result from base R function diff z <- diff(x) all.equal(y, z) # But diffs is faster benchmark(diffs(x), diff(x), replications = 100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.