interleave: Interleave Two Vectors

Description Usage Arguments Value Author(s) References Examples

Description

This function takes two vectors and merges them, by means of an in shuffle. Every other value in the result vector originates from the same source vector; values in odd-numbered positions are from vector A, while even-numbered positions are occupied by values from vector B. The ordering of the original values is preserved.

Usage

1
interleave(a, b)

Arguments

a

A vector A.

b

A second vector B.

Value

An interleaved vector with length equal to length(A) + length(B).

Author(s)

Arun Srinivasan

References

https://stackoverflow.com/questions/16443260/interleave-lists-in-r

Examples

1
2
3
4
5
a <- c(1, 2, 3)
b <- c(4, 5, 6)

interleave(a, b) # returns 1 4 2 5 3 6
interleave(as.character(a), as.character(b)) # returns "1" "4" "2" "5" "3" "6"

rpkyle/cscmisc documentation built on May 13, 2019, 12:06 p.m.