replace_head | R Documentation |
Replace initial n
values in a vector.
replace_head(v, n, r)
v |
vector. Input vector to have head replaced. |
n |
integer. Number of values at start of |
r |
String, logical, numeric etc. What to use as replacement. Should
either be a single value or vector of length |
A simple solution for replacing the initial n
values in a vector.
Replacing the initial n
values is straightforward compared to replacing
the final n
values, but this makes a nice partner function to
replace_head()
.
The v
vector is returned but with the initial n
values overwritten
by 'r.
Nicholas Carey - nicholascarey@gmail.com
replace_head
# Replace initial 5 numeric values with single value
x <- 1:10
replace_head(x, 5, 100)
# Replace initial logical with a different logical
x <- rep(TRUE, 10)
replace_head(x, 1, FALSE)
# Replace initial n with a vector of same length
x <- 1:20
replace_head(x, 5, c(100,99,98,97,96))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.