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.

______________________________________________
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