From tplate at acm.org  Thu Oct 29 16:14:59 2009
From: tplate at acm.org (Tony Plate)
Date: Thu, 29 Oct 2009 09:14:59 -0600
Subject: [Rd] what should NCOL(NULL) return?
In-Reply-To: <307b90470910290339o6b245280u56a83842acac2527@mail.gmail.com>
References: <307b90470910290339o6b245280u56a83842acac2527@mail.gmail.com>
Message-ID: <4AE9B173.7080304@acm.org>

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.
>



[Rd] what should NCOL(NULL) return?
Tony Plate