[R] create an array with rep
baptiste Auguié
ba208 at exeter.ac.uk
Sun Jul 22 13:09:08 CEST 2007
Hi,
I want to make the following array of numbers:
-3 -3 -3 -3 -3 -3 -3 -2 -2 -2 -2 -2 -2 -2 ... 3 3 3 3 3 3 3
-3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 ... -3 -2 -1 0 1 2 3
(3 would be N, a painful example to type number).
Here is my dirty attempt to do it,
> N<-3
>
> x<-c(-N:N)
>
> rj<-rbind(matrix(outer(matrix(1,1,2*N+1),x),nrow=1),rep(x,2*N+1))
>
It sort of works, but I'd like some advice on how to do it properly
as I'm very new to R and N may be big at some point.
Thanks,
baptiste
More information about the R-help
mailing list