Here is one way: > mydays <- seq(as.Date("2010-01-01"), as.Date("2010-02-01"), by="1 day") > myweekdays <- mydays[ ! weekdays(mydays) %in% c('Saturday','Sunday') ] > myweekdays [1] "2010-01-01" "2010-01-04" "2010-01-05" "2010-01-06" "2010-01-07" [6] "2010-01-08" "2010-01-11" "2010-01-12" "2010-01-13" "2010-01-14" [11] "2010-01-15" "2010-01-18" "2010-01-19" "2010-01-20" "2010-01-21" [16] "2010-01-22" "2010-01-25" "2010-01-26" "2010-01-27" "2010-01-28" [21] "2010-01-29" "2010-02-01"
This generates the sequence of days, then throws out the weekends (you could also list the weekdays instead of the weekend days and drop the "!", but I am lazy). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Ron Michael > Sent: Monday, October 04, 2010 12:08 PM > To: r-help@r-project.org > Subject: [R] Generating weekdays only > > Dear all, can anyone please tell me how to generate a sequence of days > continuously, however without considering weekends i.e. Saturday and > Sunday? I am aware of following code: > > > seq(as.Date("2010-01-01"), as.Date("2010-02-01"), by="1 day") > [1] "2010-01-01" "2010-01-02" "2010-01-03" "2010-01-04" "2010-01-05" > "2010-01-06" "2010-01-07" "2010-01-08" > [9] "2010-01-09" "2010-01-10" "2010-01-11" "2010-01-12" "2010-01-13" > "2010-01-14" "2010-01-15" "2010-01-16" > [17] "2010-01-17" "2010-01-18" "2010-01-19" "2010-01-20" "2010-01-21" > "2010-01-22" "2010-01-23" "2010-01-24" > [25] "2010-01-25" "2010-01-26" "2010-01-27" "2010-01-28" "2010-01-29" > "2010-01-30" "2010-01-31" "2010-02-01" > > However this generates all days. > Thanks for your time. > > > > [[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.