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)

Arguments

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 x).

adj

An optional value specifying any adjustments to the iterator.

Value

A vector of values.

Examples

# Pull 3 values per iteration
y <- 1:9
for (i in 1:3) {
  print(y[over(1:3, i)])
}
#> [1] 1 2 3
#> [1] 4 5 6
#> [1] 7 8 9

# 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)])
}
#> [1] 1 2
#> [1] 4 5
#> [1] 7 8

# Pull last of 3 values per iteration
# using the 'per' argument
for (i in 1:3) {
  print(y[over(3, i, per = 3)])
}
#> [1] 3
#> [1] 6
#> [1] 9

# 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)])
}
#> [1] 5 6
#> [1] 7 8