Hop along multiple inputs simultaneously relative to an index
hop_index2()
and phop_index()
represent the combination
of slide2()
and pslide()
with hop_index()
, allowing you to iterate
over multiple vectors at once, relative to an .i
-ndex with
boundaries defined by .starts
and .stops
.
hop_index2(.x, .y, .i, .starts, .stops, .f, ...) hop_index2_vec(.x, .y, .i, .starts, .stops, .f, ..., .ptype = NULL) phop_index(.l, .i, .starts, .stops, .f, ...) phop_index_vec(.l, .i, .starts, .stops, .f, ..., .ptype = NULL)
.x, .y |
Vectors to iterate over. Vectors of size 1 will be recycled. |
.i |
The index vector that determines the window sizes. It is fairly common to supply a date vector as the index, but not required. There are 3 restrictions on the index:
|
.starts, .stops |
Vectors of boundary values that make up the windows to bucket |
.f |
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. |
.ptype |
A prototype corresponding to the type of the output. If If supplied, the result of each call to If |
.l |
A list of vectors. The length of |
A vector fulfilling the following invariants:
hop_index2()
vec_size(hop_index2(.x, .y, .starts, .stops)) == vec_size_common(.starts, .stops)
vec_ptype(hop_index2(.x, .y, .starts, .stops)) == list()
hop_index2_vec()
vec_size(hop_index2_vec(.x, .y, .starts, .stops)) == vec_size_common(.starts, .stops)
vec_size(hop_index2_vec(.x, .y, .starts, .stops)[[1]]) == 1L
vec_ptype(hop_index2_vec(.x, .y, .starts, .stops, .ptype = ptype)) == ptype
phop_index()
vec_size(phop_index(.l, .starts, .stops)) == vec_size_common(.starts, .stops)
vec_ptype(phop_index(.l, .starts, .stops)) == list()
phop_index_vec()
vec_size(phop_index_vec(.l, .starts, .stops)) == vec_size_common(.starts, .stops)
vec_size(phop_index_vec(.l, .starts, .stops)[[1]]) == 1L
vec_ptype(phop_index_vec(.l, .starts, .stops, .ptype = ptype)) == ptype
# Notice that `i` is an irregular index! x <- 1:5 i <- as.Date("2019-08-15") + c(0:1, 4, 6, 7) # Manually create starts/stops. They don't have to be equally spaced, # and they don't have to be the same size as `.x` or `.i`. starts <- as.Date(c("2019-08-15", "2019-08-18")) stops <- as.Date(c("2019-08-16", "2019-08-23")) # The output size is equal to the common size of `.starts` and `.stops` hop_index2(x, i, i, starts, stops, ~data.frame(x = .x, y = .y))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.