From ripley at stats.ox.ac.uk  Tue Apr 24 13:51:57 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 24 Apr 2007 12:51:57 +0100 (BST)
Subject: [Rd] nlevels(<no factor>) is 0 and not NA
In-Reply-To: <462DE9B3.6070604@stats.uwo.ca>
References: <Pine.LNX.4.64.0704241056070.7612@localhost.localdomain>
	<462DE9B3.6070604@stats.uwo.ca>
Message-ID: <Pine.LNX.4.64.0704241247250.15882@auk.stats>

On Tue, 24 Apr 2007, Duncan Murdoch wrote:

> On 4/24/2007 4:58 AM, Torsten Hothorn wrote:
>>> nlevels(c("a", "b"))
>> [1] 0
>>
>> but the documentation in R 2.5.0 (and earlier) says
>>
>>  	If the argument is not a 'factor', 'NA' is returned.
>>
>> I hope it isn't too late, I only came across this in a lecture this
>> morning.
>
> It's too late for 2.5.0, but not for 2.5.1, or 2.6.0, ...
>
> Just to be clear:  this is a documentation error, right?  The behaviour
> is unchanged back at least as far as 2.2.1.

It is also wrong in that other objects can have levels (in which case 
nlevels() reports how many), and I think the sentence should be deleted.
In theory there ought to be a \value section like

\value{
    The length of \code{\link{levels}(x)}, which is zero if
    \code{x} has no levels. 
}

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] nlevels(<no factor>) is 0 and not NA
Prof Brian Ripley