# [R] Array dimnames

Domenico Vistocco vistocco at unicas.it
Sat Dec 15 19:30:44 CET 2007

```Sorry, there were mistakes in variable names... (I realized only after
pressed the send button)

Domenico Vistocco wrote:
> dave mitchell wrote:
>
>> Dear all,
>> Possibly a rudimentary question, however any help is greatly appreciated.  I
>> am sorting a large matrix into an array of dim(p(i),q,3).  I put each entry
>> into a corresponding matrix (1 of the 3) based on some criteria.  I figure
>> this will assist me in condensing code as I can loop through the 3rd
>> dimension of the array instead of generating 3 separate matrices and using
>> the same block of code 3 times.  My question is how to get the colnames of
>> the 3 nested matrices in the array to match the colnames of the data
>> matrix.  In other words...
>>
>>
> Denoting with array3d the array and with matrix2d the data matrix:
>
> colnames(array3d)=colnames(array3d)
>
colnames(array3d)=colnames(matrix2d)
> Otherwise, using dimnames:
> dimnames(array3d)=list(NULL,colnames(array3d),NULL)
>
dimnames(array3d)=list(NULL,colnames(matrix2d),NULL)
> You can operate using the "[" operator, that is:
> array3d[,"region",] to extract the region columns from each dimension.
>
> You obtain the same effect using the column number, i.e.
> array3d[,2,]
>
> domenico
>
>> DATA:
>>    Exp   region   Qty   Ct  ...q
>> 1   S      CB     3.55  2.15  .
>> 2   S      TG     4.16  2.18  .
>> 3   C      OO     2.36  3.65  .
>> 4   C   .           .         .
>> .   .     .           .       .
>> .   .       .           .     .
>> .   .         .           .   .
>> p   ...........................
>>
>>
>>
>> ARRAY
>> 1
>>    [,1]   [,2]    [,3] [,4]...q
>> 1   SOME DATA WILL FILL THIS   .
>> 2   .  .              .        .
>> 3   .   .              .       .
>> 4   .    .              .      .
>> .   .     .              .     .
>> .   .      .              .    .
>> .   .       .              .   .
>> P(1) ...........................
>>
>> 2
>>    [,1]   [,2]    [,3] [,4]...q
>> 1   SOME DATA WILL FILL THIS   .
>> 2   .  .              .        .
>> 3   .   .              .       .
>> 4   .    .              .      .
>> .   .     .              .     .
>> .   .      .              .    .
>> .   .       .              .   .
>> P(2) ...........................
>> 3
>>    [,1]   [,2]    [,3] [,4]...q
>> 1   SOME DATA WILL FILL THIS   .
>> 2   .  .              .        .
>> 3   .   .              .       .
>> 4   .    .              .      .
>> .   .     .              .     .
>> .   .      .              .    .
>> .   .       .              .   .
>> P(3) ...........................
>>
>> Again, how to get those [,1], [,2]... to read (and operate) in the same
>> fashion as the column names in the data matrix?  Also, am I interpreting the
>> dimensions of the array incorrectly?  Please feel free to post any helpful
>> links on the subject, as I have found "dimnames" and "array" in the R-help
>> documentation unhelpful.  Any help is greatly appreciated.
>>
>> Dave Mitchell
>> University of Illinois, Urbana-Champaign
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help