Clue: make a column representing the desired classification, and then use any of the methods you considered to do the summarizing.

One possible approach:
myframe$wend <- as.factor(ifelse(weekday( myframe$dates) %in% c("Saturday","Sunday"), "Weekend", "Weekday"))

---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

"Hu, Yinghua" <Yinghua.Hu@ask.com> wrote:

(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
_____________________________________________

R-help@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.


	[[alternative HTML version deleted]]

