Re: [R] Re :help to aggregate data

From: eugen pircalabelu <eugen_pircalabelu_at_yahoo.com>
Date: Thu, 10 Jun 2010 02:59:17 -0700 (PDT)

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

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



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.

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 Thu 10 Jun 2010 - 10:02:13 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 Thu 10 Jun 2010 - 10:10:28 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