R-alpha: apply(): R versus S

Kurt Hornik (Kurt.Hornik@ci.tuwien.ac.at)
Fri, 13 Dec 1996 16:34:05 +0100


Date: Fri, 13 Dec 1996 16:34:05 +0100
Message-Id: <199612131534.QAA26404@aragorn.ci.tuwien.ac.at>
From: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
To: r-testers@stat.math.ethz.ch
Subject: R-alpha: apply():  R versus S

I noticed the following difference between R and S(plus).

The R man page says that apply() returns an array of dimension
	c(n,dim(x))[MARGIN]
which should in any case be
	c(n,dim(x)[MARGIN])

The S man page says that the result is of dimension
	c(n,dim(x)[MARGIN])
unless n == 1;  in this case, apply() returns a vector if MARGIN has
length 1 and an array of dimension dim(x)[MARGIN] otherwise.

In fact, the current version of apply() also returns a vector if n == 1
and MARGIN has length 1, but really does return an array of dimension
c(1, dim(x)[MARGIN]) if length(MARGIN) > 1.

Is this really the desired behavior?  If not, an easy fix is to replace

	if (is.null(tdim)) 
		ansv <- array(ansv, c(pdim, d[MARGIN]))

by

	if (is.null(tdim))
		  if(pdim == 1)
		    ansv <- array(ansv, d[MARGIN])
		  else
		    ansv <- array(ansv, c(pdim, d[MARGIN]))

-k


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-