Re: [R] How to make a 2-dim array being "interpreted" as an array rather than as a matrix

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Tue, 04 Mar 2008 21:22:08 -0300

I don't know if is the best way:

a3 <- array(a2, dim=c(nrow(a2), ncol(a2), 1))

foo(a3)

On 04/03/2008, Søren Højsgaard <Soren.Hojsgaard_at_agrsci.dk> wrote:
> Dear List
>
> A 2-dimensional array seems to be "interpreted" as a matrix whereas higher dimensional arrays are interpreted as arrays, e.g.
>
> > a1 <- array(1:8,c(2,2,2))
> > class(a1)
> [1] "array"
> > a2 <- array(1:4,c(2,2))
> > class(a2)
> [1] "matrix"
>
> If I write a generic function (apologies if this is the wrong word) on arrays as
>
> foo <- function(x) UseMethod("foo")
> foo.array <- function(x) sum(x)
>
> then this fails on a 2-dimensional array:
>
> > foo(a1)
> [1] 36
> > foo(a2)
> Error in UseMethod("foo") : no applicable method for "foo"
>
> Is there any way in which I can "force" a2 to being "interpreted" as having class "array" rather than "matrix" so that foo will work on a2???
>
> Thanks in advance
> Søren
>
>
>
>
>
>
>
> ______________________________________________
> 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
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 Wed 05 Mar 2008 - 00:26:27 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 Wed 05 Mar 2008 - 01: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.

list of date sections of archive