I just had to solve this problem for myself, after not having luck with the
code posted above. I'm posting in case others need a completely general
function.
riffle <- function (a,b) {
# Interleave a & b, starting with a, without repeating.
x <- NULL; count = 1;
for (i in 1:max(length(a), length(b))) {
if (i <= length(a)) {
x[count] <- a[i];
count = count+1;
};
if (i <= length(b)) {
x[count] <- b[i];
count = count+1;
}
};
x
};
riffle( 1:10, 50:55 )
--
View this message in context:
http://n4.nabble.com/Interleaving-elements-of-two-vectors-tp795123p1691317.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.