[R] dropping factor levels in subset
Adaikalavan Ramasamy
gisar at nus.edu.sg
Mon Jun 30 03:35:50 CEST 2003
Another option is pruneLevels() in library nlme.
x <- factor( c( 0,1,2,1,2 ) )
> x
[1] 0 1 2 1 2
Levels: 0 1 2
> pruneLevels( x[-1] )
[1] 1 2 1 2
Levels: 1 2
-----Original Message-----
From: Marc Schwartz [mailto:mschwartz at medanalytics.com]
Sent: Saturday, June 28, 2003 2:31 AM
To: 'Prof Brian Ripley'
Cc: r-help at stat.math.ethz.ch; 'Nick Bond'
Subject: RE: [R] dropping factor levels in subset
>-----Original Message-----
>From: r-help-bounces at stat.math.ethz.ch
>[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Prof
>Brian Ripley
>Sent: Friday, June 27, 2003 12:11 PM
>To: Marc Schwartz
>Cc: r-help at stat.math.ethz.ch; 'Nick Bond'
>Subject: RE: [R] dropping factor levels in subset
>
>
>Re: [, drop=TRUE} for factors
>
>It's been in S-PLUS (but not S I believe) for a long time,
>probably since
>before 1994: it is in S+3.4, 1996 vintage.
>
>It appears to have been added to R around August 1998.
>
>Yes, Frank Harrell argues for the default to be true and I believe
his
>Hmisc package overrides this. Although less unsafe than it
>used to be (a
>lot more consistency checking of factor levels has been added)
>it is still
>I believe undesirable. The argument `drop.unused.levels' to
>model.frame
>will usually do all that is required. (That's another thing that is
>very-little known.)
Thanks for the clarifications.
SNIP
>> I now note that for factor objects, this is included in MASS 4 (pg
>> 19), whereas it is a footnote in MASS 3 (pg 20) and I could not
find
>> it in MASS 1 (I don't have a copy of MASS 2 to review). It is also
a
>> footnote in S Programming (pg 14). Not sure if any
>significance should
>> be attached to being a footnote versus being in the body of
>the text.
>
>None.
OK. I initially had the impression that it may have been either
chronologically associated with the addition of this method for
factors or the greater emphasis on R in MASS 4, since it moved from a
footnote to the body. I was wrong.
Also, I realized a typo in the MASS 4 page number I had above, it
should be 16.
Regards,
Marc
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list