how to extract 1x1 array slice as matrix in R?
<p>I am working with 3D arrays.  A function takes a 2D array slice (matrix) from the user and visualizes it, using row and column names (the corresponding dimnames of the array).  It works fine if the array dimensions are > 1.</p>

<p>However, if I have 1x1x1 array, I cannot extract the slice as a matrix:</p>

<pre><code>a &lt;- array(1, c(1,1,1), list(A="a", B="b", C="c"))

a[1,,]
[1] 1
</code></pre>

<p>It is a scalar with no dimnames, hence part of the necessary information is missing.  If I add <code>drop=FALSE</code>, I don't get a matrix but retain the original array:</p>

<pre><code>a[1,,,drop=FALSE]
, , C = c

   B
A   b
  a 1
</code></pre>

<p>The dimnames are here but it is still 3-dimensional.  Is there an easy way to get a matrix slice from 1x1x1 array that would look like the above, just without the third dimension:</p>

<pre><code>   B
A   b
  a 1
</code></pre>

<p>I suspect the issue is that when indexing an array, we cannot distinguish between 'take 1 value' and 'take all values' in case where 'all' is just a singleton...</p>