Skip to contents

Combine Two Vectors Alternatingly

Usage

combineAlternatingly(a, b)

Arguments

a

first vector

b

second vector

Value

vector x with all x[c(1, 3, 5, ...)] == a and all

x[c(2, 4, 6, ...)] == b

Examples

a <- paste0("a", 1:5)
b <- paste0("b", 1:5)

combineAlternatingly(a, b)
#>  [1] "a1" "b1" "a2" "b2" "a3" "b3" "a4" "b4" "a5" "b5"
combineAlternatingly(b, a)
#>  [1] "b1" "a1" "b2" "a2" "b3" "a3" "b4" "a4" "b5" "a5"

combineAlternatingly(list(a = 1, b = 2), list(c = 3, d = 4))
#> $a
#> [1] 1
#> 
#> $c
#> [1] 3
#> 
#> $b
#> [1] 2
#> 
#> $d
#> [1] 4
#>