On 20 Oct 2008, at 22:57, (Ted Harding) wrote:

I'm wondering if there's a compact way to achieve the
following. The "dream" is that one could write

 rep(c(0,1),times=c(3,4,5,6))

which would produce

# [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1

in effect "recycling" x through 'times'.

rep2 <- function (x, times) rep(rep(x, length.out=length(times)), times)

rep2(c(0,1),times=c(3,4,5,6))
 [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1

Any prizes for shortest solution? ;-)

Best,
Stefan

______________________________________________
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.

Reply via email to