[R] Excluding levels in table and xtabs
John Fox
jfox at mcmaster.ca
Wed Dec 11 17:23:03 CET 2002
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:
>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.
>
> > levels(CPIC)
>[1] "" "N" "Y"
> > levels(Manix)
>[1] "" "N" "Y"
> > xtabs(~CPIC + Manix, exclude=c("",NA))
> Manix
>CPIC N Y
> 272 4 15
> N 154 2812 1472
> Y 158 466 4870
>
> > table(CPIC, Manix, exclude=c("",NA))
>
> 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.
>
>--
>Michael Friendly friendly at yorku.ca
>York University http://www.math.yorku.ca/SCS/friendly.html
>Psychology Department
>4700 Keele Street Tel: (416) 736-5115 x66249
>Toronto, Ontario, M3J 1P3 Fax: (416) 736-5814
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>http://www.stat.math.ethz.ch/mailman/listinfo/r-help
____________________________
John Fox
Department of Sociology
McMaster University
email: jfox at mcmaster.ca
web: http://www.socsci.mcmaster.ca/jfox
More information about the R-help
mailing list