hop() is the lower level engine that powers
slide() (at least in theory).
It has slightly different invariants than
slide(), and is useful
when you either need to hand craft boundary locations, or want to compute a
result with a size that is different from
1 2 3
The vector to iterate over and apply
Vectors of boundary locations that make up the windows to bucket
If a function, it is used as is.
If a formula, e.g.
This syntax allows you to create very compact anonymous functions.
Additional arguments passed on to the mapped function.
A prototype corresponding to the type of the output.
If supplied, the result of each call to
hop() is very close to being a faster version of:
1 2 3 4 5 6 7 8
Because of this,
hop_index() is often the more useful function.
mainly exists for API completeness.
The main difference is that the start and stop values make up ranges of
possible locations along
.x, and it is not enforced that these locations
actually exist along
.x. As an example, with
hop() you can do the
following, which would be an error with
out of bounds.
1 2 3
hop() allows these out of bounds values to be fully compatible with
slide(). It is always possible to construct a
hop() call from a
call. For example, the following are equivalent:
1 2 3 4 5 6 7 8 9
A vector fulfilling the following invariants:
vec_size(hop(.x, .starts, .stops)) == vec_size_common(.starts, .stops)
vec_ptype(hop(.x, .starts, .stops)) == list()
vec_size(hop_vec(.x, .starts, .stops)) == vec_size_common(.starts, .stops)
vec_size(hop_vec(.x, .starts, .stops)[]) == 1L
vec_ptype(hop_vec(.x, .starts, .stops, .ptype = ptype)) == ptype
1 2 3 4 5 6 7 8 9 10 11
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.