title: Using an array as a subindex of a larger dimension array
body: <p>I have two arrays: P and arr, whose dimension are:</p>
  
  <pre><code>&gt; dim(arr)
  [1] 8 2
  
  &gt; dim(P)
  [1] 3 8 2
  </code></pre>
  
  <p>Then, arr has values </p>
  
  <pre><code>&gt; arr
        [,1][,2]
  [1,]    2    1
  [2,]    1    2
  [3,]    1    3
  [4,]    1    4
  [5,]    2    5
  [6,]    2    6
  [7,]    2    7
  [8,]    2    8
  </code></pre>
  
  <p>which are intended to be a subindex of the P matrix. So, what I'd like to do is something like this </p>
  
  <pre><code>P[1,arr] 
  </code></pre>
  
  <p>to obtain the values</p>
  
  <pre><code>P[1,2,1]
  P[1,1,2]
  P[1,1,3]
  ...
  P[1,2,8]
  </code></pre>
  
  <p>, but P[1,arr] gives the error </p>
  
  <pre><code>Error in P[1, arr] : incorrect number of dimensions
  </code></pre>
  
  <p>How can I use arr as a subindex of P?</p>