I have the following vectors example:
v1 <- c("AA", "BB")
v2 <- c("AA", "BB", "CCC")
Note that the length of each vector can be varied.
What I want to do is to interleave each vector with a string:
linker <- "xxx"
Resulting in this:
c("AA", "xxx", "BB")
c("AA","xxx", "BB", "xxx", "CCC")
How can I achieve that?
>Solution :
You could use an rbind trick here:
v1 <- c("AA", "BB")
v2 <- c("AA", "BB", "CCC")
linker <- "xxx"
head(c(rbind(v2, linker)), -1)
[1] "AA" "xxx" "BB" "xxx" "CCC"