Re: [R] accessing arrays

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 03 Jan 2007 - 17:47:36 GMT

Or you could define it as your own class and define your own print and other methods, e.g.

> X <- structure(array(1:8, c(2,2,2)), class = "twomats")
> attr(X, "DIMNAMES") <- list(list(c("No", "Yes"), c("No", "Yes")),
+ dimnames = list(c("No", "Yes"), c("big", "small")))

>
> print.twomats <- function(x, ...) {

+         Y <- list(X[,,1], X[,,2])
+ for(i in 1:2) {
+ dimnames(Y[[i]]) <- attr(x, "DIMNAMES")[[i]]
+ print(Y[[i]])
+ }
+ }

>
> X

    No Yes
No 1 3
Yes 2 4

    big small

No    5     7
Yes   6     8




On 1/3/07, Patrick Burns <pburns@pburns.seanet.com> wrote:
> You can't do that. If you want to have different labels
> on the first two dimensions, then a 3-dimensional array
> doesn't seem to be the natural data structure.
>
> I would suggest two matrices held in a list.
>
> Patrick Burns
> patrick@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
>
> downunder03 wrote:
>
> >hi all. how can i adress a array directly. for example i wanna give array 1
> >other labels than array 2. How can I overcome this problem?
> >
> >...this doesn't work
> >
> >tab <- array(1:8, c(2, 2, 2))
> >dimnames(tab[,,1]) <- list(c("No","Yes"), c("No","Yes"),c("ARRAY1"))
> >dimnames(tab[,,2]) <- list(c("big","small"), c("small","big"),c("ARRAY2"))
> >
> >
> >
> >
> >
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 Thu Jan 04 04:53:07 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 04 Jan 2007 - 01:30:27 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.