[R] Re :help to aggregate data

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Jun 10 10:47:20 CEST 2010


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.



More information about the R-help mailing list