Skip to content
Prev 361923 / 398506 Next

[FORGED] Re: Generate list if sequence form two vector element

There's also

mapply(a, b, FUN=seq, SIMPLIFY=FALSE)

(turn off simplication so that you don't unexpectedly get a matrix whenever all elements of results have same length. This also affects apply()-based solutions.)

...except that according to original spec, one should ensure a < b. So

myseq <- function(a,b) if(a<b) a:b else b:a
mapply(a, b, FUN=myseq, SIMPLIFY=FALSE)

-pd