[R] Create sequence given start and end vector

Kevin Ummel kevinummel at gmail.com
Sat Dec 12 20:27:30 CET 2009


How can I create the following without the 'for' loop?

start=c(1,10,20)

end=c(4,15,27)

out=c()

for (i in 1:length(start)) {
	out=c(out,start[i]:end[i])
	}
out
 [1]  1  2  3  4 10 11 12 13 14 15 20 21 22 23 24 25 26 27

I know there must be an easier (and, hopefully, faster) way.

Many thanks in advance,
Kevin Ummel

Central European University
Department of Environmental Science and Policy




More information about the R-help mailing list