From nilsson.henric at gmail.com  Wed Apr 12 15:35:43 2017
From: nilsson.henric at gmail.com (Henric Winell)
Date: Wed, 12 Apr 2017 15:35:43 +0200
Subject: [Rd] "table(droplevels(aq)$Month)" in manual page of droplevels
In-Reply-To: <58EE202A020000A10002595B@gwsmtp1.uni-regensburg.de>
References: <58EE202A020000A10002595B@gwsmtp1.uni-regensburg.de>
 <58EE202A020000A10002595B@gwsmtp1.uni-regensburg.de>
Message-ID: <b66fe849-bb8d-f00d-87e5-553f866d57e0@gmail.com>

On 2017-04-12 14:40, Ulrich Windl wrote:

> The last line of the example in droplevels' manual page seems to be
> incorrect to me. I think it should read:
> "table(droplevels(aq$Month))". Amazingly (I don't understand) both
> variants seem to produce the same result (R 3.3.3): ---

The manual says that "The function 'droplevels' is used to drop unused 
levels from a 'factor' or, more commonly, from factors in a data frame." 
and, as documented, the 'droplevels' generic has methods for objects of 
class "data.frame" and "factor".  So, your being amazed is a bit 
surprising given that 'aq' is a data frame.


Henric Winell



>> aq <- transform(airquality, Month = factor(Month, labels =
>> month.abb[5:9])) aq <- subset(aq, Month != "Jul") table(aq$Month)
> 
> May Jun Jul Aug Sep 31  30   0  31  30
>> table(droplevels(aq)$Month)
> 
> May Jun Aug Sep 31  30  31  30
>> table(droplevels(aq$Month))
> 
> May Jun Aug Sep 31  30  31  30
>> 
> --- For the sake of learners, try to keep the examples simple and
> useful, even though you experts want to impress the newbees...
> 
> Ulrich
> 
> ______________________________________________ R-devel at r-project.org
> mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] "table(droplevels(aq)$Month)" in manual page of droplevels
Henric Winell