[R] Array dimnames

Tony Plate tplate at acm.org
Mon Dec 17 19:27:37 CET 2007


I can't quite understand what you're having difficulty with (is it 
constructing the array, or coping with the different 'matrices' having 
different column names, or something else?)

However, your sample data looks like it has a mixture of factor (region) 
and numeric data (Qty), so you're probably storing it in a data frame. 
AFAIK, there is no 3d object in R that can store mixed-type data like a 
data frame can.  An array object in R has to have the same data type for 
every column etc.

-- Tony Plate

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...
> 
> 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
> Undergraduate: Statistics and Mathematics,
> 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
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list