[R] fridays date to date

Marc Schwartz marc_schwartz at me.com
Thu Mar 1 21:30:10 CET 2012


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,
> 
> Ben


Days <- 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



More information about the R-help mailing list