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

From: huron <thomas.j.best_at_gmail.com>
Date: Wed, 18 May 2011 20:47:08 -0700 (PDT)


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.

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 19 May 2011 - 05:21:40 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 May 2011 - 06:50:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive