From ligges at statistik.uni-dortmund.de  Sun Sep  7 19:15:18 2003
From: ligges at statistik.uni-dortmund.de (ligges@statistik.uni-dortmund.de)
Date: Sun Sep  7 18:14:43 2003
Subject: [Rd] bug in crossprod? (PR#4092)
Message-ID: <200309071615.h87GFIJH002161@pubhealth.ku.dk>

Duncan Murdoch wrote:
> On Sun, 7 Sep 2003 17:01:00 +0200 (MET DST), you wrote:
> 
> 
>># The last line of following code produces a segmentation fault:
>>
>>x <- 1:10
>>f <- gl(5,2)
>>mns <- tapply(x,f,mean)
>>crossprod(mns) #to get sum of squares of mns.
>># Of course sum(mns^2) is more straightforward.
> 
> 
> This appears to have been fixed in r-devel:  I get 
> 
> 
>>crossprod(mns) #to get sum of squares of mns.
> 
> Error in crossprod(mns) : invalid type for dimname (must be a vector)


You get it sometimes - randomly, when R doesn't crash. The bug is still 
present in R-devel (2003-09-05).

Simple example:

  x <- array(1:2, dim=2)
  dimnames(x) <- list(1:2)
  crossprod(x)

The point is indeed in getting dimnames for one-dimensional arrays.


Uwe Ligges



> If you really want the answer, you should use
> 
>  crossprod(as.matrix(mns))
> 
> since crossprod is documented to require a matrix argument.  This
> works in 1.7.1 too.
> 
> Duncan Murdoch
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel


[Rd] bug in crossprod? (PR#4092)
ligges@statistik.uni-dortmund.de