[R] Problem with xtabs(), exclude=NULL, and counting NA's

Webb Sprague webb.sprague at gmail.com
Thu Sep 24 18:49:45 CEST 2009


>> Also see addNA.

Works great. Sometimes R drives me crazy, but Hadley, you make it much
easier for me....

> That is nice. The addNA function does not exactly jump off the page for the
> (too) casual reader. In the context of the OP's original problem, these
> lines of code are illustrative:

Here is an example from the actual dataset:

> xtabs(pwgtp~addNA(cut(pums.mex$JWMNP, c(0, 19, 65, Inf), include.lowest=TRUE)))
addNA(cut(pums.mex$JWMNP, c(0, 19, 65, Inf), include.lowest = TRUE))
  [0,19]  (19,65] (65,Inf]     <NA>
   39053    46787     2521    61914
> xtabs(pwgtp~(cut(pums.mex$JWMNP, c(0, 19, 65, Inf), include.lowest=TRUE)))
cut(pums.mex$JWMNP, c(0, 19, 65, Inf), include.lowest = TRUE)
  [0,19]  (19,65] (65,Inf]
   39053    46787     2521

Thanks to all!




More information about the R-help mailing list