View source: R/S03_Utilities.R
every | R Documentation |
Extracts a sequence of values from a vector in regular increments.
every(x, step = 2, start = 1)
every(x, step = 2, start = 1) <- value
x |
A vector of values. |
step |
The size of the increment between indices in the sequence. |
start |
The index at which to start the sequence. |
value |
A vector of new values to assign
to |
A vector of values extracted from x
.
# Extract every other value
# at odd positions
every(1:10)
# Extract every other value
# at even positions
every(1:10, , 2) # Note double commas
# Extract every 3rd value starting
# from 6th position
every(1:12, 3, 6)
# Replace values at even
# positions with 0
x <- 1:10
every(x, , 2) <- 0
x
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.