[R] Aggregate daily data into weekly sums

antonio rodriguez antonio.raju at gmail.com
Mon Jul 23 23:49:13 CEST 2007


Or,

z<-mydata #zoo object

new.time <- as.Date(7 * floor(as.numeric(time(z))/7) + 7)
z2 <- aggregate(z, new.time, mean)




Henrique Dallazuanna escribió:
> Hi,
>
> Perhaps you can try:
>
>   
>> df
>>     
>          Date Amount
> 1  2007-06-01      1
> 2  2007-06-01      1
> 3  2007-06-04      2
> 4  2007-06-05      2
> 5  2007-06-11      3
> 6  2007-06-12      3
> 7  2007-06-12      3
> 8  2007-06-13      3
> 9  2007-06-13      3
> 10 2007-06-18      4
> 11 2007-06-18      4
> 12 2007-06-25      5
> 13 2007-06-28      5
>
> df_ok <- aggregate(df$Amount, by=list(df$Amount), FUN=sum)
> levels(df_ok$Group.1)<- paste("2007/06/Week", 1:5, sep="")
>   
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>   


-- 
=====
Por favor, si me mandas correos con copia a varias personas, 
pon mi dirección de correo en copia oculta (CCO), para evitar 
que acabe en montones de sitios, eliminando mi privacidad, 
favoreciendo la propagación de virus y la proliferación del SPAM. Gracias.
-----
If you send me e-mail which has also been sent to several other people,
kindly mark my address as blind-carbon-copy (or BCC), to avoid its
distribution, which affects my privacy, increases the likelihood of
spreading viruses, and leads to more SPAM. Thanks.
=====
Antes de imprimir este e-mail piense bien si es necesario hacerlo: El medioambiente es cosa de todos.
Before printing this email, assess if it is really needed.



More information about the R-help mailing list