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

huron thomas.j.best at gmail.com
Thu May 19 05:47:08 CEST 2011


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 following:

for (m in 1:M) {
  for (p in 1:P) {
    for (q in 1:Q) {
      A[m,,p,q] = A[m,,p,q] + x
    }
  }
}

Thanks in advance!

--
View this message in context: http://r.789695.n4.nabble.com/Add-a-vector-to-the-values-in-a-specific-dimension-of-an-array-tp3534730p3534730.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list