insert_vector_entry: Insert entry in vector

View source: R/insert_vector_entry.R

insert_vector_entryR Documentation

Insert entry in vector

Description

This function inserts a value into a vector.

Usage

insert_vector_entry(v, x, p)

Arguments

v

[atomic()]
A vector.

x

[atomic(1)]
The entry to be added.

p

[⁠integer())⁠]
The position(s) where to add the value, one or more of:

  • p = 0 appends the value left

  • p = length(v) appends the value right

  • p = n inserts the value between the n-th and (n + 1)-th entry of v.

Value

A vector.

See Also

Other vector helpers: check_numeric_vector(), check_probability_vector(), chunk_vector(), match_numerics(), permutations(), split_vector_at(), subsets(), vector_occurrence()

Examples

v <- 1:3
x <- 0
insert_vector_entry(v, x, 0)
insert_vector_entry(v, x, 1)
insert_vector_entry(v, x, 2)
insert_vector_entry(v, x, 3)

### also multiple positions
insert_vector_entry(v, x, 0:3)

### also trivial case
insert_vector_entry(integer(), integer(), integer())

oeli documentation built on Oct. 16, 2024, 5:08 p.m.