patapouf_ai patapouf_ai - 8 months ago 107
R Question

How to find Previous Sunday in R

It seems the Internet has not answered this question for R yet:

If I have a date. Say the 20th of march: as.Date("2015-03-20")
how do I get, in R, the previous Sunday?
i.e., in the above example, as.Date("2015-03-15").

Answer Source

Here is one approach:

d <-  as.Date("2015-03-18")
prev.days <- seq(d-6,d,by='day')
prev.days[weekdays(prev.days)=='Sunday']
# [1] "2015-03-15"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download