Description Usage Arguments Value Examples
Written in C++, this function should always run faster than
diff
for calculating differences between adjacent values
of a numeric vector. For integer vectors, diff1_i
should run
even faster.
1 | diff1_n(x)
|
x |
Numeric vector. |
Numeric vector.
1 2 3 4 5 6 7 8 9 | # In general, diff1_n is much faster than diff
x <- rnorm(1000)
all.equal(diff(x), diff1_n(x))
benchmark(diff(x), diff1_n(x), replications = 3000)
# For integer vectors, diff1_i should be even faster
x <- rpois(1000, lambda = 5)
all.equal(diff(x), diff1_i(x))
benchmark(diff(x), diff1_n(x), diff1_i(x), replications = 3000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.