[R] < 0 x 0 matrix >

Duncan Murdoch murdoch at stats.uwo.ca
Fri Sep 4 12:55:38 CEST 2009


baptiste auguie wrote:
> it's documented as "unexpected"
>
> ?diag
> Note
>
> Using diag(x) can have unexpected effects if x is a vector that could be of
> length one. Use diag(x, nrow = length(x)) for consistent behaviour.
>
>
> And the result follows from this part,
>
>     else if (length(x) == 1L && nargs() == 1L) {
>         n <- as.integer(x)
>         x <- 1
>     }
>   

Looks like the man page is wrong:  it says diag(0.9) should produce a 
1x1 matrix, but as the code shows, it produces a 0x0 one.
I'll fix it.

Duncan Murdoch
>
> baptiste
>
> 2009/9/4 Markku Karhunen <markku.karhunen at helsinki.fi>
>
>   
>> 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
>>
>> BR, Markku Karhunen
>> researcher
>> University of Helsinki
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>     
>
>
>
>   
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list