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

2009-09-24 Thread ws
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

now this doesn't even work 

 table(wtf, exclude=NULL)
wtf
   [0,10)   [10,20)   [20,30)   [30,40)   [40,50)   [50,60)   [60,70)   [70,80)
 8562 15297  9666  6659  3583   667  1357   238
  [80,90)  [90,100) [100,110) [110,120) [120,130) [130,140) [140,150) [150,160)
   61   311571995 7 3   111
[180,190)  NA
  161 62161

Compare: 
 xtabs (~ wtf, exclude=NULL, na.action=na.pass)
wtf
   [0,10)   [10,20)   [20,30)   [30,40)   [40,50)   [50,60)   [60,70)   [70,80)
 8562 15297  9666  6659  3583   667  1357   238
  [80,90)  [90,100) [100,110) [110,120) [120,130) [130,140) [140,150) [150,160)
   61   311571995 7 3   111
[180,190)
  161

 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
day24
svn rev49384
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.


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

2009-09-24 Thread David Winsemius


On Sep 23, 2009, at 5:11 PM, ws 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
  11   10134


now this doesn't even work 


Try:

wtf - factor(x, levels(c(levels(wtf), NA), exclude=NULL)
xtabs (~ wtf, exclude=NULL, na.action=na.pass)

--  
David




table(wtf, exclude=NULL)

wtf
  [0,10)   [10,20)   [20,30)   [30,40)   [40,50)   [50,60)
[60,70)   [70,80)
8562 15297  9666  6659  3583   667   
1357   238
 [80,90)  [90,100) [100,110) [110,120) [120,130) [130,140) [140,150)  
[150,160)
  61   311571995 7  
3   111

[180,190)  NA
 161 62161

Compare:

xtabs (~ wtf, exclude=NULL, na.action=na.pass)

wtf
  [0,10)   [10,20)   [20,30)   [30,40)   [40,50)   [50,60)
[60,70)   [70,80)
8562 15297  9666  6659  3583   667   
1357   238
 [80,90)  [90,100) [100,110) [110,120) [120,130) [130,140) [140,150)  
[150,160)
  61   311571995 7  
3   111

[180,190)
 161


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
day24
svn rev49384
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.


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.


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

2009-09-24 Thread David Winsemius


On Sep 24, 2009, at 3:06 AM, David Winsemius wrote:



On Sep 23, 2009, at 5:11 PM, ws 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
 11   10134


now this doesn't even work 


Try:

wtf - factor(x, levels(c(levels(wtf), NA), exclude=NULL)
xtabs (~ wtf, exclude=NULL, na.action=na.pass)


Note: that will mean that sum(is.na(wtf)) will return 0 and  
is.na(wtf)- will no longer have any valid targets.




-- David



table(wtf, exclude=NULL)

wtf
 [0,10)   [10,20)   [20,30)   [30,40)   [40,50)   [50,60)
[60,70)   [70,80)
   8562 15297  9666  6659  3583   667   
1357   238
[80,90)  [90,100) [100,110) [110,120) [120,130) [130,140) [140,150)  
[150,160)
 61   311571995 7  
3   111

[180,190)  NA
161 62161

Compare:

xtabs (~ wtf, exclude=NULL, na.action=na.pass)

wtf
 [0,10)   [10,20)   [20,30)   [30,40)   [40,50)   [50,60)
[60,70)   [70,80)
   8562 15297  9666  6659  3583   667   
1357   238
[80,90)  [90,100) [100,110) [110,120) [120,130) [130,140) [140,150)  
[150,160)
 61   311571995 7  
3   111

[180,190)
161

--
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.


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

2009-09-24 Thread hadley wickham
 wtf - factor(x, levels(c(levels(wtf), NA), exclude=NULL)
 xtabs (~ wtf, exclude=NULL, na.action=na.pass)

Also see addNA.

Hadley


-- 
http://had.co.nz/

__
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

2009-09-24 Thread David Winsemius


On Sep 24, 2009, at 10:06 AM, hadley wickham wrote:


wtf - factor(x, levels(c(levels(wtf), NA), exclude=NULL)
xtabs (~ wtf, exclude=NULL, na.action=na.pass)


Also see addNA.



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:


 xtabs(~addNA(wkhp), x, exclude=NULL, na.action=na.pass)
addNA(wkhp)
  20   30   40   45   60 NA
   11   10134
 x$wtf - cut(x$wkhp, breaks=seq(20, 80, by=20) )
 xtabs( ~ addNA(wkhp), x)
addNA(wkhp)
  20   30   40   45   60 NA
   11   10134
 xtabs( ~ addNA(wtf), x)
addNA(wtf)
(20,40] (40,60] (60,80]NA
 11   4   0   5


Hadley


--
http://had.co.nz/


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.


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

2009-09-24 Thread Webb Sprague
 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

2009-09-23 Thread ws
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   296571989 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   296571989 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
day24
svn rev49384
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.


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

2009-09-23 Thread Webb Sprague
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

2009-09-05 Thread Webb Sprague
 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.


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

2009-09-05 Thread Mark Difford

 I must say that this is slightly odd behavior to require both
 na.action= AND exclude=.  Does anyone know of a justification?

Not strange at all.

?options

na.action, sub head Options set in package stats. You need to override the
default setting.


ws-7 wrote:
 
 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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Problem-with-xtabs%28%29%2C-exclude%3DNULL%2C-and-counting-NA%27s-tp25304142p25305878.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Problem with xtabs(), exclude=NULL, and counting NA's

2009-09-04 Thread ws
Hi all,

I cannot get xtabs to count NA's like I expect.  Below is a sample session, and 
note that the last two calls to xtabs() yield exactly the same thing.

I am running R-2.5.0 -- if there was a bug in xtabs that got fixed, I would 
love 
to know about it. If there is a bug tracker somewhere, I can file it too. It 
isn't my fault that the server is so ridiculously outdated, but I would have to 
install a more recent version in my home directory to fix this, so I don't 
really want to.

Note also that I know various approaches to working around the problem, so I 
don't need help with that, just with whether or not xtabs works with nas or not.

TIA

$ x=as.data.frame(list(wkhp=WKHP[1:20]))
$ x
   wkhp
1NA
2NA
360
4NA
520
640
730
840
940
10   40
11   45
12   40
13   40
14   NA
15   40
16   40
17   40
18   60
19   60
20   40
$ xtabs(~wkhp, x)
wkhp
20 30 40 45 60
 1  1 10  1  3
$ xtabs(~wkhp, x, exclude=NULL)  # Look -- no counts of NAs!
wkhp
20 30 40 45 60
 1  1 10  1  3

__
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

2009-09-04 Thread David Winsemius


On Sep 4, 2009, at 7:49 PM, ws wrote:


Hi all,

I cannot get xtabs to count NA's like I expect.  Below is a sample  
session, and

note that the last two calls to xtabs() yield exactly the same thing.

I am running R-2.5.0 -- if there was a bug in xtabs that got fixed,  
I would love
to know about it. If there is a bug tracker somewhere, I can file it  
too. It
isn't my fault that the server is so ridiculously outdated, but I  
would have to
install a more recent version in my home directory to fix this, so I  
don't

really want to.

Note also that I know various approaches to working around the  
problem, so I
don't need help with that, just with whether or not xtabs works with  
nas or not.


TIA

$ x=as.data.frame(list(wkhp=WKHP[1:20]))
$ x
  wkhp
1NA
2NA
360
4NA
520
640
730
840
940
10   40
11   45
12   40
13   40
14   NA
15   40
16   40
17   40
18   60
19   60
20   40
$ xtabs(~wkhp, x)
wkhp
20 30 40 45 60
1  1 10  1  3
$ xtabs(~wkhp, x, exclude=NULL)  # Look -- no counts of NAs!
wkhp
20 30 40 45 60
1  1 10  1  3


 xtabs(~wkhp, x, exclude=NULL, na.action=na.pass)
wkhp
  20   30   40   45   60 NA
   11   10134

--
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.