Hello, How do I get the dates of all Fridays between two dates? thanks, Ben [[alternative HTML version deleted]]
Inelegant, but here's one way: d1 <- Sys.Date() d2 <- Sys.Date() + 100 library(lubridate) d <- seq(d1, d2, by = "day") d[wday(d)==6] Michael On Thu, Mar 1, 2012 at 3:02 PM, Ben quant <ccquant at gmail.com> wrote:> Hello, > > How do I get the dates of all Fridays between two dates? > > thanks, > > Ben > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
On Mar 1, 2012, at 2:02 PM, Ben quant wrote:> Hello, > > How do I get the dates of all Fridays between two dates? > > thanks, > > BenDays <- seq(from = as.Date("2012-03-01"), to = as.Date("2012-07-31"), by = "day")> str(Days)Date[1:153], format: "2012-03-01" "2012-03-02" "2012-03-03" "2012-03-04" ... # See ?weekdays> Days[weekdays(Days) == "Friday"][1] "2012-03-02" "2012-03-09" "2012-03-16" "2012-03-23" "2012-03-30" [6] "2012-04-06" "2012-04-13" "2012-04-20" "2012-04-27" "2012-05-04" [11] "2012-05-11" "2012-05-18" "2012-05-25" "2012-06-01" "2012-06-08" [16] "2012-06-15" "2012-06-22" "2012-06-29" "2012-07-06" "2012-07-13" [21] "2012-07-20" "2012-07-27" HTH, Marc Schwartz