Skip to content

Excluding levels in table and xtabs

5 messages · Michael Friendly, John Fox, Thomas Lumley +1 more

#
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.
[1] ""  "N" "Y"
[1] ""  "N" "Y"
Manix
CPIC        N    Y
     272    4   15
   N 154 2812 1472
   Y 158  466 4870
Manix
CPIC        N    Y
     272    4   15
   N 154 2812 1472
   Y 158  466 4870

The only way I can exclude them is by

t <- table(CPIC, Manix)
t <- t[-1,-1]

that's not to hard in this case, but my application is to a much
larger table where this gets unweildly.
#
Dear Mike,

You could read the file specifying the na.strings argument to read.csv. 
Does that do what you need?

Regards,
  John
At 10:15 AM 12/11/2002 -0500, Michael Friendly wrote:
____________________________
John Fox
Department of Sociology
McMaster University
email: jfox at mcmaster.ca
web: http://www.socsci.mcmaster.ca/jfox
#
On Wed, 11 Dec 2002, Michael Friendly wrote:

            
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.

	-thomas
Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle
^^^^^^^^^^^^^^^^^^^^^^^^
- NOTE NEW EMAIL ADDRESS
#
Hola!
Thomas Lumley wrote:
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.
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.

Kjetil Halvorsen
#
On Wed, 11 Dec 2002, kjetil halvorsen wrote:

            
Yes, you're right.
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