Re: [R] Array dimnames

From: Tony Plate <tplate_at_acm.org>
Date: Mon, 17 Dec 2007 11:27:37 -0700

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.

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.
>



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. Received on Mon 17 Dec 2007 - 18:30:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Dec 2007 - 19:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.