Re: [R] ask for help how to get accumulate contingency table?

From: alex chin <rfrqchin_at_hotmail.com>
Date: Wed, 19 Mar 2008 10:39:29 -0400

I am still looking for an efficient way to get accumulated contingency table. Becasue it is huge data and permutate with covariate. it will be very slow if I use loops. Can somebody give me a help? Thanks.  

xj> Date: Tue, 18 Mar 2008 10:43:27 -0400> From: markleeds_at_verizon.net> Subject: RE: [R] ask for help how to get accumulate contingency table?> To: rfrqchin_at_hotmail.com> > I'm not at work so I'm not sure it will work but you can try below.> > I am assuming the result of table(data1) is a list so> > tablelist<-table(data1)> > cumtablelist<-list()> > for ( tablenum in (2:length(tablelist)) {> > > cumtablelist[[tablenum]]<-cumtablelist[[tablenum-1]]+cumtablelist[[tablenum]> ]> > }> > print(cumtablelist)> > > > > -----Original Message-----> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On> Behalf Of alex chin> Sent: Tuesday, March 18, 2008 9:42 AM> To: r-help_at_r-project.org> Subject: [R] ask for help how to get accumulate contingency table?> > > Hi, I post the question again.> x<-rep(c(2,3,4),20)> y<-sample(rep(c(0,1),30))> tr<-rep(c(1:5),6)> data1<-data.frame(x,y,tr)> data1<-data1[order(data1$tr),]> > data1> x y tr> 2 1 1> 4 0 1> 3 1 1> 2 1 1 > 4 1 1> 3 1 1> 2 0 1> 4 0 1> 3 0 1> 2 0 1> 4 0 1> 3 1 1> 3 0 2> 2 0 2> >table(data1)> tr = 1> y> x 0 1> 2 2 2> 3 1 3> 4 3 1> tr = 2> y> x 0 1> 2 2 2> 3 2 2> 4 1 3> Question: How to get accumulate contingency table by variable "tr" in data1?> e.g. how to get the following results.> tr = 1 > y> x 0 1 > 2 2 2 > 3 1 3> 4 3 1> tr = 2 > y> x 0 1 > 2 4 4> 3 3 6> 4 4 4> ... > Thank you for your help. xj. > _________________________________________________________________> Helping your favorite cause is as easy as instant messaging. You IM, we> give.> > [[alternative HTML version deleted]]> > 
_________________________________________________________________
Helping your favorite cause is as easy as instant messaging. You IM, we give.

        [[alternative HTML version deleted]]



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. Received on Wed 19 Mar 2008 - 14:52:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 19 Mar 2008 - 15:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive