How to find Previous Sunday in R

后端 未结 4 693
说谎
说谎 2020-12-16 14:45

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 Sun

4条回答
  •  盖世英雄少女心
    2020-12-16 15:04

    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"
    

提交回复
热议问题