[R] How to sum and group data by DATE in data frame
Mohamed Lajnef
Mohamed.lajnef at inserm.fr
Wed Sep 9 13:36:42 CEST 2009
Hi Clair,
try to use this code
aggregate(toto$Income,by=list((substr(toto$Date,1,7))),sum)
Regards
mohamed
clair.crossupton at googlemail.com a écrit :
> Dear all,
>
> Lets say I have a data frame as follows:
>
>
>
>> Date <- as.Date(c('2006-08-23', '2006-08-30', '2006-09-06', '2006-09-13', '2006-09-20'))
>> Income <- c(73.79, 72.46, 76.32, 72.43, 72.62)
>> data.frame(Date, Income)
>>
> Date Income
> 1 2006-08-23 73.79
> 2 2006-08-30 72.46
> 3 2006-09-06 76.32
> 4 2006-09-13 72.43
> 5 2006-09-20 72.62
>
>
> is there a way to group the data by month (summing the values in each
> month), i.e.
>
> Date Income
> 2006-08 146.25
> 2006-09 221.37
>
> Thanks in advance,
> C.C.
>
> ______________________________________________
> 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.
>
>
--
Mohamed Lajnef
INSERM Unité 955.
40 rue de Mesly. 94000 Créteil.
Courriel : Mohamed.lajnef at inserm.fr
tel. : 01 49 81 31 31 (poste 18470)
Sec : 01 49 81 32 90
fax : 01 49 81 30 99
More information about the R-help
mailing list