Re: [R] Add a vector to the values in a specific dimension of an array

2011-05-18 Thread Bill.Venables
:47 PM To: r-help@r-project.org Subject: [R] Add a vector to the values in a specific dimension of an array Hello, A simple question, although I can't find an answer via my google/forum search: I have a 4-dimensional array; call it A[1:M,1:N,1:P,1:Q]. I have a vector x that is N by 1.

Re: [R] Add a vector to the values in a specific dimension of an array

2011-05-18 Thread Ian Gow
Hi: Reordering the dimensions, then doing a vectorized addition, then reordering (back) again is faster, it seems. > m <- 20; n <- 30; p <- 40; q <- 30 > a <- NA > length(a) <- m * n * p * q > dim(a) <- c(m, n, p, q) > x <- 1:n > a[1:m,,1:p,1:q] <- 0 > b <- a > > # Approach 1 > system.time({ +

[R] Add a vector to the values in a specific dimension of an array

2011-05-18 Thread huron
Hello, A simple question, although I can't find an answer via my google/forum search: I have a 4-dimensional array; call it A[1:M,1:N,1:P,1:Q]. I have a vector x that is N by 1. I would like to "quickly" add x to the 2nd dimension of A; in other words, I want a quicker way of doing the followi