[R] means by year, month and day
Jianling Fan
fanjianling at gmail.com
Sun Jul 17 23:42:10 CEST 2016
Hello Tom,
try aggregate() or cast(). Both works.I prefer the latter.
library(reshape)
desc<-melt(mydata, measure.vars=c("WDI","R.WSP", "D.GST", "PRES",
"ATMP", "DEWP"),
id.vars=c("X.YY","MM","DD"))
summary<-cast(desc, X.YY+MM+DD~variable, mean)
On 17 July 2016 at 06:22, Tom Mosca <tom at vims.edu> wrote:
> Hello Good Folk,
>
> My dataframe looks like this:
>> mydata
> X.YY MM DD hh WDI R.WSP D.GST PRES ATMP DEWP
> 1 2015 1 1 0 328 3.6 4.5 1028.0 3.8 -3.5
> 2 2015 1 1 1 300 2.1 2.7 1027.9 3.7 -4.4
> 3 2015 1 1 2 264 2.4 2.9 1027.7 3.6 -4.5
> 4 2015 1 1 3 230 4.1 4.5 1027.4 4.2 -3.8
> 5 2015 1 1 4 242 8.1 9.2 1026.6 4.4 -3.1
> 6 2015 1 1 5 262 9.3 10.1 1026.6 4.1 -3.8
> 7 2015 1 1 6 267 8.6 9.6 1026.3 4.2 -3.8
> 8 2015 1 1 7 264 9.3 9.9 1026.1 3.9 -2.8
> 9 2015 1 1 8 268 8.2 9.1 1026.1 3.5 -3.0
> 10 2015 1 1 9 272 8.8 9.6 1025.4 3.2 -3.3 …
>
> The first four columns are year, month, day, hour (0 – 23). I wish to take the means of the next six columns (WDIR, WSPD, GST, PRES, ATMP and DEWP) by year, month and day. That is, I want daily averages.
>
> Please help. Thank you.
>
> Tom
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
--
Jianling Fan
樊建凌
More information about the R-help
mailing list