This function inserts a value into a vector.
Arguments
- v
[
atomic()]
Avector.- x
[
atomic(1)]
The entry to be added.- p
[
integer()]
The position(s) where to add the value, one or more of:p = 0appends the value leftp = length(v)appends the value rightp = ninserts the value between then-th and(n + 1)-th entry ofv.
Examples
v <- 1:3
x <- 0
insert_vector_entry(v, x, 0)
#> [1] 0 1 2 3
insert_vector_entry(v, x, 1)
#> [1] 1 0 2 3
insert_vector_entry(v, x, 2)
#> [1] 1 2 0 3
insert_vector_entry(v, x, 3)
#> [1] 1 2 3 0
### also multiple positions
insert_vector_entry(v, x, 0:3)
#> [1] 0 1 0 2 0 3 0
### also trivial case
insert_vector_entry(integer(), integer(), integer())
#> integer(0)
