Skip to contents

This function inserts values into a vector, lengthening the overall vector. It is different from, say, x[1:3] <- c('a', 'b', 'c') which simply replaces the values at indices 1 through 3.

Usage

insert(x, into, at, warn = TRUE)

Arguments

x

Vector of numeric, integer, character, or other values of the class of x to be inserted.

into

Vector of values into which to insert x.

at

Vector of positions (indices) where x should be inserted. If the length of x is shorter than the length of at, then values in x will be recycled and a warning produced.

warn

If TRUE, provide warnings.

Value

Vector.

See also

Examples


x <- -1:-3
into <- 10:20
at <- c(1, 3, 14)
insert(x, into, at)
#>  [1] -1 10 -2 11 12 13 14 15 16 17 18 19 20 -3

insert(-1, into, at)
#> Warning: Length of x is shorter than the length of at. Recycling x.
#>  [1] -1 10 -1 11 12 13 14 15 16 17 18 19 20 -1