On Mon, Jun 18, 2012 at 01:24:21AM +0800, 李红旺 wrote: > > a<-c(1,4) > > a > [1] 1 4 > > b<-a*5 > > b > [1] 5 20 > > a is a very long vector , how can i get c(1:5,4:20)? i do not want to > use a loop.
Hi. How large are the numbers in a? If max(a) is not too large, try the following. a <- c(1, 4, 3, 1) ma <- max(a) b <- matrix(a, nrow=4*ma+1, ncol=length(a), byrow=TRUE) + matrix(0:(4*ma), nrow=4*ma+1, ncol=length(a)) out <- c(b[b <= rep(5*a, each=4*ma+1)]) out [1] 1 2 3 4 5 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 3 4 5 [26] 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 Hope this helps. Petr Savicky. ______________________________________________ R-help@r-project.org 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.