Skip to content
Prev 138520 / 398506 Next

How to make a 2-dim array being "interpreted" as an array rather than as a matrix

Dear List
 
A 2-dimensional array seems to be "interpreted" as a matrix whereas higher dimensional arrays are interpreted as arrays, e.g.
[1] "array"
[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:
[1] 36
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