[R] Excluding levels in table and xtabs
Thomas Lumley
tlumley at u.washington.edu
Thu Dec 12 20:17:02 CET 2002
On Wed, 11 Dec 2002, kjetil halvorsen wrote:
> Hola!
>
> Thomas Lumley wrote:
> >
> > On Wed, 11 Dec 2002, Michael Friendly wrote:
> >
> > > I'm trying to form contingincy tables among a set of character variables
> > > which were read from a .csv file and
> > > have missing represented as "". I want to exclude the missing levels
> > > from the table.
> >
> > I think this is a bug. The exclude= argument doesn't work for factors,
> > because the argument is passed to factor(), and its exclude argument has
> > a different format when the main argument is a factor.
>
> I dot think that is correct. table doesnt call factor on factors, so the
> exclude argument doesnt get used at all. I had the oposite problem as
> the original poster.
Yes, you're right.
> To include NA's as a level in a table. Why should't table simply call
> factor also on factor arguments, so the exclude argument to table get
> used in this case to. I modifyed table to Table doing this, and it
> works, the only problem being that NA is not labelled in the table.
I think there's another problem: this will exclude empty levels, which we
deliberately don't do (that's probably why we don't call factor()).
The real solution may be slightly more complicated.
-thomas
More information about the R-help
mailing list