View source: R/S03_Utilities.R
over | R Documentation |
A function that takes a sequence of values and scales it by an iterator. Useful when extracting a set of multiple values within a loop.
over(x, iter, per = NULL, adj = -1)
x |
A sequence of values (converted to integers). |
iter |
An iterator value, typically the variable defined within a loop. |
per |
An optional value specifying the
increment by which to adjust the range
(defaults to the maximum value of |
adj |
An optional value specifying any adjustments to the iterator. |
A vector of values.
# Pull 3 values per iteration
y <- 1:9
for (i in 1:3) {
print(y[over(1:3, i)])
}
# Pull first 2 of each 3 values per iteration
# using the 'per' argument
for (i in 1:3) {
print(y[over(1:2, i, per = 3)])
}
# Pull last of 3 values per iteration
# using the 'per' argument
for (i in 1:3) {
print(y[over(3, i, per = 3)])
}
# Pull 2 values for final 2 sets using the
# 'adj' argument
y <- 1:8
for (i in 1:2) {
print(y[over(1:2, i, adj = 1)])
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.