every.Rd
Extracts a sequence of values from a vector in regular increments.
every(x, step = 2, start = 1)
every(x, step = 2, start = 1) <- value
A vector of values.
The size of the increment between indices in the sequence.
The index at which to start the sequence.
A vector of new values to assign
to x
at the sequence of indices.
A vector of values extracted from x
.
# Extract every other value
# at odd positions
every(1:10)
#> [1] 1 3 5 7 9
# Extract every other value
# at even positions
every(1:10, , 2) # Note double commas
#> [1] 2 4 6 8 10
# Extract every 3rd value starting
# from 6th position
every(1:12, 3, 6)
#> [1] 6 9 12
# Replace values at even
# positions with 0
x <- 1:10
every(x, , 2) <- 0
x
#> [1] 1 0 3 0 5 0 7 0 9 0