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

From: Bjørn-Helge Mevik <bhs2_at_mevik.net>
Date: Tue 31 Aug 2004 - 17:49:20 EST


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

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue Aug 31 17:53:31 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:00:00 EST