On 10/19/2010 11:47 AM, Rainer M Krug wrote: >> x[n %% length(x)] gives you the same answer as rep(x, length.out=n)[n], >> without having to create the longer vector. >> n %% length(x) may return 0 and in that case, x[n %% length(x)] will not give the result you expect. x[((n - 1) %% length(x)) + 1] might be what you want.