[R] Summing daily values by weekday and weekend
Hu, Yinghua
Yinghua.Hu at ask.com
Fri Jul 22 03:43:19 CEST 2011
(Sorry for reposting. Please delete previous msgs. Thanks!)
Hi, all
Here I created a data frame like
mydates<- seq(as.Date("2010-05-29"), length = 43, by = "day")
myvalues<-runif(43,0,1)
myframe<-data.frame(dates=mydates, day=weekdays(dates), value=myvalues)
dates day value
1 2010-05-29 Saturday 0.14576143
2 2010-05-30 Sunday 0.37669604
3 2010-05-31 Monday 0.74813943
4 2010-06-01 Tuesday 0.34677680
…
39 2010-07-06 Tuesday 0.69944349
40 2010-07-07 Wednesday 0.62712550
41 2010-07-08 Thursday 0.76714978
42 2010-07-09 Friday 0.72078298
43 2010-07-10 Saturday 0.80048954
How do I add weekday and weekend value in each week? I want a resulting data frame like
Dates day value
2010-05-29 weekend 0.5225
2010-05-31 weekday 2.2352
…
2010-07-05 weekday 3.xxxx
2010-07-10 weekend 0.8005
The closest I find is
http://www.mail-archive.com/r-help@r-project.org/msg130580.html
But this one only summing values in each week, it does not sum values by weekday and weekend. I have been thinking of using functions such as aggregate, ddply, but without a clue. Anybody who can give some suggestions will be highly appreciated. Thanks!
Yinghua
More information about the R-help
mailing list