Hello, Or ?aggregate
stdate<-c(rep(1,5),rep(2,5)) domaindesc<-c(1,1,1,2,2,2,3,3,3,3) logins<-sample(1:10, 10) dummy.data<-as.data.frame(cbind(stdate,domaindesc,logins)) aggregate(dummy.data[,3], by=list(dummy.data[,1],dummy.data[,2]), FUN=sum) # same result as tapply, but with only levels that have observation # tapply(dummy.data[,3], dummy.data[,1:2], sum) Eugen Pircalabelu (0032)471 842 140 (0040)727 839 293 ----- Original Message ---- From: Uwe Ligges <lig...@statistik.tu-dortmund.de> To: Mohan L <l.mohan...@gmail.com> Cc: r-help@r-project.org Sent: Thu, June 10, 2010 10:47:20 AM Subject: Re: [R] Re :help to aggregate data On 10.06.2010 04:48, Mohan L wrote: > Dear All, > > I have the data some thing like this, I am showing here three days data > only: > >> dummy.data<- read.table(file='dummy.txt',sep='', header=TRUE) >> dummy.data > StDate Domaindesc Logins > 1 05/01/10 xxx 10 > 2 05/01/10 xxx 45 > 3 05/01/10 xxx 2 > 4 05/01/10 yyy 45 > 5 05/01/10 yyy 20 > 6 05/01/10 yyy 22 > 7 05/01/10 zzz 34 > 8 05/01/10 zzz 54 > 9 05/01/10 zzz 1 > 10 05/01/10 zzz 0 > 11 05/02/10 yyy 32 > 12 05/02/10 xxx 40 > 13 05/02/10 zzz 23 > 14 05/02/10 yyy 5 > 15 05/02/10 zzz 12 > 16 05/02/10 xxx 19 > 17 05/02/10 xxx 23 > 18 05/02/10 xxx 11 > 19 05/02/10 yyy 9 > 20 05/02/10 zzz 0 > 21 05/03/10 xxx 2 > 22 05/03/10 xxx 21 > 23 05/03/10 xxx 6 > 24 05/03/10 yyy 45 > 25 05/03/10 yyy 43 > 26 05/03/10 yyy 34 > 27 05/03/10 yyy 41 > 28 05/03/10 zzz 31 > 29 05/03/10 zzz 19 > 30 05/03/10 zzz 27 > > I trying to aggregate(sum) the Logins based on Domaindesc,StDate. I need > like this : > > Domaindesc 05/01/10 05/02/10 05/03/10 > xxx 57 93 29 > yyy 87 46 122 > zzz > > Any help will be greatly appreciated. See ?tapply, e.g.: tapply(dummy.data[,3], dummy.data[,1:2], sum) Uwe Ligges > Thanks for your time. > Mohan L > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. ______________________________________________ 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.