tapply not simplifying to vector? (PR#320)

About this list Date view Thread view Subject view Author view Other groups

Subject: tapply not simplifying to vector? (PR#320)
Date: Thu 11 Nov 1999 - 13:56:34 EST

Message-Id: <199911110356.EAA27675@pubhealth.ku.dk>

Hi, all.

The help file for tapply says that if simplify is true, and the result of
the calculation is always a scalar, then tapply will return a vector.


> t1 <- tapply(runif(10), rep(1:5, 2), mean)
> is.vector(t1)
> is.array(t1)
[1] TRUE

I have found this in version 0.65.1 on an SGI running Irix 6.5, and on a
Mac running Linux-PPC. I've also seen it on an Intel machine running
RedHat 6.0.

I noticed this because some results that I expected to be vectors couldn't
be combined into a data frame (Error: can't coerce array into a

It seems that the check and conversion simply never happens. One way to
fix this is to simply add these few lines to the end of the function (just
before the value "ansmat" is returned:

  if(length(dim(ansmat)) == 1){
    dim(ansmat) <- NULL
    names(ansmat) <- namelist[[1]]

I wouldn't be surprised to find that there's a more elegant way to do
this. Perhaps ansmat[index] should be returned instead of ansmat? But I
haven't tested this extensively, so I don't know whether it might break
something else.

Hope this report helps.

Thanks for the terrific software.

Matt Wiener

r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch

About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:10 EST