[R] How can I calculate conditional mean in a large dataset including date data

bogdan romocea br44114 at gmail.com
Thu Feb 1 15:12:45 CET 2007


days <- seq(as.Date("1970/1/1"), as.Date("2003/12/31"), "days")
temp <- rnorm(length(days), mean=10, sd=8)
tapply(temp, format(days,"%Y-%m"), mean)
tapply(temp, format(days,"%b"), mean)


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Majid Iravani
> Sent: Thursday, February 01, 2007 8:11 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] How can I calculate conditional mean in a large
> dataset including date data
>
> Dear R users,
>
> I have a dataframe with two columns: first column is date data (e.g.
> 1/1/2000 with character format: daily data from 1/1/1970 till
> 31/12/2003)
> and second column is temperature value. Now I'd like to
> calculate mean for
> each month in a year (i.e. May 2001, June 1997) and mean for
> each month in
> all of years. As the number of days in some months is
> different from others
> I could not write appreciate command for this. Therefore I
> would greatly
> appreciate if somebody can help me in this case
>
> Thank you
> Majid
> --------------------------------------------------------------
> ------------------
>   Majid Iravani
>   PhD Student
>   Swiss Federal Research Institute WSL
>   Research Group of Vegetation Ecology
>   Zürcherstrasse 111  CH-8903 Birmensdorf  Switzerland
>   Phone: +41-1-739-2693
>   Fax: +41-1-739-2215
>   Email: Majid.iravani at wsl.ch
> http://www.wsl.ch/staff/majid.iravani/
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list