[Rd] what should NCOL(NULL) return?

Tony Plate tplate at acm.org
Thu Oct 29 16:14:59 CET 2009


Hiroyuki Kawakatsu wrote:
> Hi,
>
> I get (using r50188)
>
>   
>> nrow(NULL)
>>     
> NULL
>   
>> NROW(NULL)
>>     
> [1] 0
>   
>> ncol(NULL)
>>     
> NULL
>   
>> NCOL(NULL)
>>     
> [1] 1
>
> The last seems 'wrong' to me, though matrix(NA, 0, 1) appears to be
> well defined.
>   
Seems consistent with the documentation, which says:


      Description

|nrow| and |ncol| return the number of rows or columns present in |x|. 
|NCOL| and |NROW| do the same treating a vector as 1-column matrix.

Based on ?NCOL alone, I guess one might be able to quibble about how 
NULL should be treated, as the docs do describe the argument as "x a 
vector, array or data frame."  However, it's pretty common for functions 
that work with vectors and arrays to treat NULL the same as numeric(0).

-- Tony Plate

>   
>> blackhole = matrix(NA, 0, 1)
>> blackhole[,1] = 5
>> blackhole
>>     
>      [,1]
>
> h.
>



More information about the R-devel mailing list