[R] matrix conformity with matrix 1x1 and scalars

From: Andres Legarra <alegarra_at_neiker.net>
Date: Tue 23 Aug 2005 - 20:30:30 EST

I am calculating this thing with vectors (b) and matrices (G,P): b'G/sqrt(b'Pb)
where the denominator is a quadratic form and therefore always a scalar.

In Scilab, it is quite simple:
However, in R, the denominator is an (1x1)matrix and R claims it is non conformable and I have to use drop() or as.numeric(). Like this:
> b = 1:2
> G=diag(1,2)
> P=diag(2,2)
> (t(b)%*%G) / drop( sqrt( t(b)%*%P%*%b ) )

          [,1] [,2]
[1,] 0.3162278 0.6324555

So far, so good. My problem is solved. However I found a little bit annoying that R is not so "clever" as to realize that b'Pb can be interpreted as a scalar. I wonder :
would it be worth considering the implementation in R of "recycling 1x1 matrix to scalars if appropriate"? Just to leave the question on the ground...



Andres Legarra
Apdo. 46
Vitoria-Gasteiz 01080 Spain

Andres Legarra Albizu
Apdo. 46
Vitoria-Gasteiz 01080 Spain
phone: +34 945 121323
fax: +34 945 281422
e-mail: alegarra@neiker.net

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Aug 23 20:34:46 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:55 EST