[R] Using tabs in output instead of spaces

2009-10-12 Thread ws
Is there a way to have xtabs and friends use tabs in their output to separate 
columns rather than spaces?  It would be great for importing into other 
software.

TIA!

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


[R] Errors and line numbers in scripts?

2009-09-17 Thread ws
Is there a way to have R return the line number in a script when it errors out? 
 

I call my script like:

$ R --vanilla  script.R  output.txt

I seem to remember a long discussion about this at some point, but I can't 
remember the outcome.

Tx

__
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] pyramid.plot: x-axis scale

2009-07-31 Thread ws
 Hi ws,
 You could tweak pyramid.plot in the plotrix package to do this.

I guess I will live without...

Unless you can spell the process out for doing that -- where is the source,
where would the package download be on my machine before (Mac OS X), who would I
send a working patch to.  If (the maintainer, right?) think it matters I can do
that, but I probably need a little handholding.

__
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] pyramid.plot: x-axis scale

2009-07-29 Thread ws
Hi R-ers

Does anyone know how if there is a way to force pyramid plot where 
you determine the bottom axis range?  I want to compare many 
different pyramids, so I am hoping to force the bottom axis range
from 0% to 10%.

Here is the code so far, if it matters:

mk.pyr = function(data, pumas=NULL, fb.class=NULL, info=) {
# Makes population pyramids
# Assumes certain columns names in data -- SEX, AGEF, PUMA

males.i = data$SEX==1
females.i = data$SEX==1

if (is.null(pumas)) {
xy.pop = 100*as.double(prop.table(xtabs(pwgtp~AGEF, 
data[males.i,])))
xx.pop = 100*as.double(prop.table(xtabs(pwgtp~AGEF, 
  data[females.i,])))
 mytitle = sprintf(Population Pyramid for all pumas. %s., 
info)

} else {
pumas.i = data$PUMA %in% pumas
xy.pop = 100*as.double(prop.table(
   xtabs(pwgtp~AGEF, data[males.i  pumas.i,])))
xx.pop = 100*as.double(prop.table(
   xtabs(pwgtp~AGEF, data[females.i  pumas.i ,])))
mytitle = sprintf(Population Pyramid for %s, 
 paste(paste(pumas, collapse=, ), ., info, .))
}
  agelabels-c(0-4,5-9,10-14,15-19,20-24,
  25-29,30-34,35-39,40-44,45-49,
  50-54,55-59,60-64,65-69,70-74,
   75-79,80-44,85+)
  xycol-color.gradient(.5,.5,.5,18)
  xxcol-color.gradient(.5,.5,.5,18)
  par(mar=pyramid.plot(xy.pop,xx.pop,labels=agelabels,
main=mytitle,xycol=xycol,xxcol=xxcol))
}

__
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] Transparency and pyramid.plot

2009-07-29 Thread ws
Hi all

Another question related to my earlier -- how might I get transparency to work 
with pyramid.plot in library(plotrix)?  I can't figure it out, and the help 
page 
says it is there but doesn't give an example.

Thanks!

__
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] Assigning rank based on total count

2009-07-27 Thread ws
 I am using ACS micro data (PUMS) with one of the columns as a 
 factor for the place of birth (POBPF).  I would like to create 
 a column (POBR) containing a rank 
 corresponding to the place of the observation 
 in the POBPF rankings.  

I wrote a blog entry on my solution:

http://oregondemographics.wordpress.com/2009/07/25/adding-a-ranking-column-to-a-
data-frame-of-observations/

__
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] Assigning rank based on total count

2009-07-23 Thread ws
Hi all,

I am using ACS micro data (PUMS) with one of the columns as a 
factor for the place of birth (POBPF).  I would like to create 
a column (POBR) containing a rank 
corresponding to the place of the observation 
in the POBPF rankings.  For example, 
if a person is from Oregon, Oregon is 
the most popular Place of Birth, so each 
person who came from Oregon should have a 1 
in their POBR.  Each row from 
California would have POBR 2, etc.  

This way I can subset on the most populous sending 
places when doing analyses.

For the life of me I can't figure this out.  
I think some combination of sort(), 
xtabs() and merge() should work, 
but my brain seems to be fried.

Tx

__
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] Assigning rank based on total count

2009-07-23 Thread ws
 
 Here's a way to get to your solution, but it's not very pretty:
 
 testdfr - data.frame(POB=c(Oregon,Oregon,Oregon,New
 York,California,California))
 
 nstates - length(unique(testdfr$POB))
 testdfr$ POBR - c(nstates:1)[table(testdfr$POB)][testdfr$POB]

Hmm  I will have to think on that for a while  An ugly
solution is still better than no solution, but that doesn't quite 
make sense to me yet.

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