[R] < 0 x 0 matrix >

Markku Karhunen markku.karhunen at helsinki.fi
Fri Sep 4 12:45:27 CEST 2009


True. Should have read ?diag.

However, this provokes a more general question: Is there some way I  
can declare some scalar and _all its functions_ as matrices?

For instance, I would like to

A = as.matrix(0.98)
B = function(A)
C = diag(sqrt(B))

so that all scalars are explicitly [1,1] matrices.

BR, Markku

> On Fri, Sep 4, 2009 at 11:25 AM, Markku
> Karhunen<markku.karhunen at helsinki.fi> wrote:
>> Hi,
>>
>> Does anybody know, what is going on here?
>>
>>> diag(sqrt(1))
>>
>>     [,1]
>> [1,]    1
>>>
>>> diag(sqrt(0.3333))
>>
>> <0 x 0 matrix>
>>>
>>> sqrt(1)
>>
>> [1] 1
>>>
>>> sqrt(0.3333)
>>
>> [1] 0.5773214
>>
>
>  Read the help for diag yet?
>
>     'diag' has four distinct usages:
> ...
>         3.  'x' is a scalar (length-one vector) and the only argument
>            it a square identity matrix of size given by the scalar.
> ...
>
> So diag(0.1) becomes diag(0) which is a 0-size matrix. Try diag(2.4)
>
> Barry
>
>




More information about the R-help mailing list