[R] Is there a faster way to change parts of this array?

Sven C. Koehler schween at snafu.de
Thu Nov 23 20:15:57 CET 2006


Hello,

I have another question on accessing arrays:

| a<- array(0, c(10000, 100, 10))
| b <- c(1,4)
| for (i in 1:10000) { for (j in 1:100) { a[i,j,b] <- (1:10)[b] }}

Is there a way to replace the nested for loops by a faster operation?

I tried to use `a[1:10000, 1:100, b] <- (1:10)[b]' but that sets values
in the array differently.

Also I am wondering whether setting any of the `--min-vsize=vl --max-vsize=vu
--min-nsize=nl --max-nsize=nu --max-ppsize=N' parameters on the
commandline should make the `array(0, c(10000, 100, 10))' operation any
quicker.

Best,

Sven



More information about the R-help mailing list