[R] Tabulation and missing values

From: David Scott <d.scott_at_auckland.ac.nz>
Date: Wed 04 Oct 2006 - 16:10:56 GMT

I think this is one for Gabor. I don't seem to be able to find my way to an answer despite numerous rereadings of factor and table.

Here is a toy example:

### Some data

EthnicCode <- c("European/Other", NA, "European/Other", "European/Other",

                 "Pacific", "European/Other", "European/Other",
                 "European/Other", "Maori", "Maori", "European/Other",
                 "European/Other", "Asian", "Pacific")

### I don't want the categories in the default order
### I also want to be able to include or exclude NA
### argument exclude controls inclusion of NA
table(EthnicCode)
table(EthnicCode,exclude=NULL)

### Creating a factor allows reordering
EthnicFactor <- factor(EthnicCode, exclude="") levels(EthnicFactor) <- list("Maori"="Maori","Pacific"="Pacific",
                                 "Asian"="Asian",
                                 "Europ/Other"="European/Other",
                                     is.na="NA")

### I can tabulate with categories in the desired order
table(EthnicFactor[,drop=TRUE])
### But I can't seem to include the missing observations
table(EthnicFactor,exclude=NULL)

David Scott


David Scott	Visiting (Until January 07)
 		Department of Probability and Statistics
 		The University of Sheffield
 		The Hicks Building
 		Hounsfield Road
 		Sheffield S3 7RH
 		United Kingdom
Phone:	+44 114 222 3908
Email:	d.scott@auckland.ac.nz

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Oct 05 02:20:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 04 Oct 2006 - 17:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.