Re: [R] Problem with xtabs(), exclude=NULL, and counting NA's
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 3905346787 252161914 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] 3905346787 2521 Thanks to all! __ R-help@r-project.org 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.
Re: [R] Problem with xtabs(), exclude=NULL, and counting NA's
Note that the variable below has been generated with cut(), if that matters. On Wed, Sep 23, 2009 at 2:34 PM, ws webb.spra...@gmail.com wrote: Webb Sprague webb.sprague at gmail.com writes: xtabs(~wkhp, x, exclude=NULL, na.action=na.pass) wkhp 20 30 40 45 60 NA 1 1 10 1 3 4 (Forgive me for the repost, but I just joined the R list, so maybe this will go through.) Now the above doesn't work! See : table(JWMNP.cut, exclude=NULL) JWMNP.cut [0,10) [10,20) [20,30) [30,40) [40,50) [50,60) [60,70) [70,80) 8345 14708 9314 6317 3437 649 1287 232 [80,90) [90,100) [100,110) [110,120) [120,130) [130,140) [140,150) [150,160) 58 296 57 19 89 6 3 108 [160,170) [170,180) [180,190) [190,200) [200,Inf] NA 0 0 154 0 0 60888 xtabs(~JWMNP.cut, exclude=NULL, na.action=na.pass) JWMNP.cut [0,10) [10,20) [20,30) [30,40) [40,50) [50,60) [60,70) [70,80) 8345 14708 9314 6317 3437 649 1287 232 [80,90) [90,100) [100,110) [110,120) [120,130) [130,140) [140,150) [150,160) 58 296 57 19 89 6 3 108 [160,170) [170,180) [180,190) [190,200) [200,Inf] 0 0 154 0 0 version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 9.2 year 2009 month 08 day 24 svn rev 49384 language R version.string R version 2.9.2 (2009-08-24) __ R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] Problem with xtabs(), exclude=NULL, and counting NA's
xtabs(~wkhp, x, exclude=NULL, na.action=na.pass) wkhp 20 30 40 45 60 NA 1 1 10 1 3 4 Thanks! I must say that this is slightly odd behavior to require both na.action= AND exclude=. Does anyone know of a justification? Shouldn't it be changed? vent Ah well, if R were internally consistent or corresponded to typical programming Unix practices, it just wouldn't feel the same ... /vent Cheers! -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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.