You can measure the array after it is filled (in one-dimensional, vector order)
Emulation of a 1-dimensional fragment of the question, here, how can this be done with higher dimensions.
> x=c() > tmp=c(1,2) > n=6 > for (i in seq(1, by=2, length=n)) x[i:(i+1)] =tmp; > dim(x) = c(2,n) > x [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 1 1 1 1 1 [2,] 2 2 2 2 2 2 >
Instead of using i:(i+1) as an index, it may be preferable to use seq(i, length=2) or even better, seq(i, length=length(tmp)) for a more general approach, as shown below (for example with 4 x 7 array)
> x=c() > tmp=c(1,2,3,4) > n=7 > for (i in seq(1, by=length(tmp), length=n)) x[seq(i, length=length(tmp))] = tmp; > dim(x) = c(length(tmp),n) > x [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 1 1 1 1 1 1 1 [2,] 2 2 2 2 2 2 2 [3,] 3 3 3 3 3 3 3 [4,] 4 4 4 4 4 4 4 >
We can also get a similar result by rearranging x with cbind / rbind, as follows.
> tmp=c(1,2) > n=6 > x=rbind(tmp) > for (i in 1:n) x=rbind(x, tmp); > x [,1] [,2] tmp 1 2 tmp 1 2 tmp 1 2 tmp 1 2 tmp 1 2 tmp 1 2 tmp 1 2
Note: you can get rid of the names "tmp" (this is a side effect of rbind) using > dimnames(x)=NULL