Jeff,

Thanks for the hint. It is a good solution.

Thanks!

From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us]
Sent: Thursday, July 21, 2011 7:00 PM
To: Hu, Yinghua; r-help@r-project.org
Subject: Re: [R] Summing daily values by weekday and weekend

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:<jdnew...@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...@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                         v

 alue
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]]

______________________________________________
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.

Reply via email to