[Rd] bug in crossprod? (PR#4092)

ligges at statistik.uni-dortmund.de ligges at statistik.uni-dortmund.de
Sun Sep 7 19:15:18 MEST 2003


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 at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list