[Rd] Dimension of apply(X, MARGIN, FUN) when FUN returns a matrix

Bjørn-Helge Mevik bhs2 at mevik.net
Tue Aug 31 09:49:20 CEST 2004


Dear all,

apply(X, MARGIN, FUN, ...) returns an array of dimension
c(n, dim(X)[MARGIN]) when FUN returns a vector of length n > 1.

Matrices and arrays are also vectors, so if FUN returns a matrix or an
array, apply returns an array of dimension c(n, dim(X)[MARGIN]) as
above.  This is in accordance with the description of apply in the
Blue Book, and also how Splus works (at least v6.0).

I am curious: why was it decided not to return an array of dimension
c(dim(result.of.FUN), dim(X)[MARGIN]) when FUN returns a matrix or an
array?

(This is not meant as criticism.  I am sure there is a good reason; I
just cannot see it.)

-- 
Bjørn-Helge Mevik



More information about the R-devel mailing list