[R] adding tables [partial solution]

Roy Mendelssohn roy.mendelssohn at noaa.gov
Tue Dec 10 01:20:43 CET 2013


Is this what you are after?

http://www.statmethods.net/management/merging.html

-Roy
On Dec 9, 2013, at 4:09 PM, Ross Boylan <ross at biostat.ucsf.edu> wrote:

> Answering myself...
> On Mon, 2013-12-09 at 15:59 -0800, Ross Boylan wrote:
>> Can anyone recommend a good way to add tables?
> For count data, which were my main concern, it looks as if tabulate with
> nbins will work.  I'm not sure how this works with a cross-classifying
> factor, which I will also need.  It's possible the factor may have
> missing values in some tabulations as well.
> 
> For the one dimensional case
>> t1 <- tabulate(c(1, 2, 2, 4), nbins=5)
>> t2 <- tabulate(c(2, 3, 5), nbins=5)
>> t1
> [1] 1 2 0 1 0
>> t2
> [1] 0 1 1 0 1
>> t1+t2
> [1] 1 3 1 1 1
> 
>> Ideally I would like
>> t1 <- table(x1)
>> t2 <- table(x2)
>> t1+t2
>> 
>> It t1 and t2 have the same levels this works fine, but I need something
>> that will work even if they differ, e.g.,
>>> t1
>> 
>> 1 2 4 5
>> 2 1 1 1
>>> t2 <- table(c(10, 11, 12, 13))
>>> t1+t2  # apparently does simple vector addition
>> 
>> 1 2 4 5
>> 3 2 2 2
>> whereas I want
>> 1 2 4 5 10 11 12 13
>> 2 1 1 1  1  1  1  1
>> 
> 
> ______________________________________________
> R-help at 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.

**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: Roy.Mendelssohn at noaa.gov (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.



More information about the R-help mailing list