[R] Is this an artifact of using "which"?

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Mon Apr 14 16:37:55 CEST 2008


> > The (imho) unintuitive behaviour is to do with the subsetting function 

> > [.factor, not which.  There are a couple of workarounds:
> > 
> In that case, your intuition needs readjustment....
> 
> There are other systems which (de facto) drop unused levels by default,
> and it is a real pain to work around, especially for subgroup analyses.
> E.g. there is no way to get PROC FREQ in SAS to include a count of zero,
> and barplots of ratings fro 0 to 10 lose columns "randomly" in SPSS
> (this _can_ be worked around, though).
> 
> Anyways, it is illogical: There's no reason that a tabulation of gender
> distribution for (say) tenured CS professors should suddenly pretend
> that the female gender does not exist!

I didn't mean to be a troll, and I can certainly see the virtue in 
preserving levels for the cases as you described, but it was something 
that caught me out me when I first learned R.  Having the levels of a 
factor as "the values that my categorical data takes", rather than "the 
_possible_ values that my categorical data takes" was more natural to me. 
The important thing is that it is possible to include or drop the unused 
levels easily as required.

Btw, has the behaviour of the drop argument to '[' changed recently?  I 
seem to remember that drop=TRUE didn't remove unused factor levels in 
older versions, though my memory may be mistaken.

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list