Re: [R] Implementing R's recycling rule

2010-10-19 Thread Erich Neuwirth
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

Re: [R] Implementing R's recycling rule

2010-10-19 Thread Rainer M Krug
On Tue, Oct 19, 2010 at 11:30 AM, wrote: > > x <- c(1, 2, 3) > > n <- 10 > > ## so using the recycling rules, I would like to get from FUN(x, n)==1 > > ## I am doing: > > xRecycled <- rep(x, length.out=n)[n] > > > > This works, but it seems to me that I am missing something really basic > here >

Re: [R] Implementing R's recycling rule

2010-10-19 Thread Richard . Cotton
> x <- c(1, 2, 3) > n <- 10 > ## so using the recycling rules, I would like to get from FUN(x, n)==1 > ## I am doing: > xRecycled <- rep(x, length.out=n)[n] > > This works, but it seems to me that I am missing something really basic here > - is there more straightforward way of doing this? x[n

[R] Implementing R's recycling rule

2010-10-19 Thread Rainer M Krug
Hi I want to use R's recycling rule. At the moment I am using the following: x <- c(1, 2, 3) n <- 10 ## so using the recycling rules, I would like to get from FUN(x, n)==1 ## I am doing: xRecycled <- rep(x, length.out=n)[n] This works, but it seems to me that I am missing something really basic