Learn R Programming

oeli (version 0.5.2)

insert_vector_entry: Insert entry in vector

Description

This function inserts a value into a vector.

Usage

insert_vector_entry(v, x, p)

Value

A vector.

Arguments

v

A vector.

x

A single value (i.e., an atomic vector of length 1), the entry to be added.

p

An integer, the position where to add the entry:

  • 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.

Can also be a vector of multiple positions.

Examples

Run this code
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())

Run the code above in your browser using DataLab