Today I was putting some code together that made plots from slices of a 3-dimensional array object aa. A couple of the dimensions in aa had names defined by named vectors. For example:
<span>></span><span> aa </span><span>=</span><span> array</span><span>(</span><span>runif</span><span>(</span><span>2</span><span>*</span><span>3</span><span>*</span><span>4</span><span>),</span><span> <br> dim</span><span>=</span><span>c</span><span>(</span><span>2</span><span>,</span><span>3</span><span>,</span><span>4</span><span>),</span><span> <br> dimnames</span><span>=</span><span>list</span><span>(</span><span>id </span><span>=</span><span> c</span><span>(</span><span>good</span><span>=</span><span>'id1'</span><span>,</span><span> evil</span><span>=</span><span>'id2'</span><span>),</span><span> <br> x </span><span>=</span><span> c</span><span>(</span><span>1</span><span>,</span><span>2</span><span>,</span><span>3</span><span>),</span><span> <br></span><span>var</span><span> </span><span>=</span><span> c</span><span>(</span><span>up</span><span>=</span><span>'a'</span><span>,</span><span> dn</span><span>=</span><span>'b'</span><span>,</span><span> lt</span><span>=</span><span>'c'</span><span>,</span><span> rt</span><span>=</span><span>'d'</span><span>)))</span><span><br></span><span>></span><span> str</span><span>(</span><span>aa</span><span>)</span><span><br> num </span><span>[</span><span>1</span><span>:</span><span>2</span><span>,</span><span> </span><span>1</span><span>:</span><span>3</span><span>,</span><span> </span><span>1</span><span>:</span><span>4</span><span>]</span><span> </span><span>0.0138</span><span> </span><span>0.2942</span><span> </span><span>0.7988</span><span> </span><span>0.3465</span><span> </span><span>0.8751</span><span> </span><span>...</span><span><br></span><span>-</span><span> attr</span><span>(*,</span><span> </span><span>"dimnames"</span><span>)=</span><span>List</span><span> of </span><span>3</span><span><br></span><span>..</span><span>$ id </span><span>:</span><span> </span><span>Named</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>2</span><span>]</span><span> </span><span>"id1"</span><span> </span><span>"id2"</span><span><br></span><span>..</span><span> </span><span>..-</span><span> attr</span><span>(*,</span><span> </span><span>"names"</span><span>)=</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>2</span><span>]</span><span> </span><span>"good"</span><span> </span><span>"evil"</span><span><br></span><span>..</span><span>$ x </span><span>:</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>3</span><span>]</span><span> </span><span>"1"</span><span> </span><span>"2"</span><span> </span><span>"3"</span><span><br></span><span>..</span><span>$ </span><span>var</span><span>:</span><span> </span><span>Named</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>4</span><span>]</span><span> </span><span>"a"</span><span> </span><span>"b"</span><span> </span><span>"c"</span><span> </span><span>"d"</span><span><br></span><span>..</span><span> </span><span>..-</span><span> attr</span><span>(*,</span><span> </span><span>"names"</span><span>)=</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>4</span><span>]</span><span> </span><span>"up"</span><span> </span><span>"dn"</span><span> </span><span>"lt"</span><span> </span><span>"rt"</span>
Thus, I could access “aliases” for dimension names in id and var by:
<span>></span><span> names</span><span>(</span><span>dimnames</span><span>(</span><span>aa</span><span>)</span><span>$id</span><span>)</span><span><br></span><span>[</span><span>1</span><span>]</span><span> </span><span>"good"</span><span> </span><span>"evil"</span><span><br></span><span>></span><span> names</span><span>(</span><span>dimnames</span><span>(</span><span>aa</span><span>)</span><span>$var</span><span>)</span><span><br></span><span>[</span><span>1</span><span>]</span><span> </span><span>"up"</span><span> </span><span>"dn"</span><span> </span><span>"lt"</span><span> </span><span>"rt"</span>
The code ...
[Read more...]