如何在R中找到上一个星期日 [英] How to find Previous Sunday in R
本文介绍了如何在R中找到上一个星期日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎Internet尚未回答R的问题:
It seems the Internet has not answered this question for R yet:
如果我有约会。 3月20日说:as.Date( 2015-03-20)
如何在R中获得上一个星期日?
,即在上面的示例中为as.Date( 2015-03-15)。
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").
推荐答案
此处是一种方法:
d <- as.Date("2015-03-18")
prev.days <- seq(d-6,d,by='day')
prev.days[weekdays(prev.days)=='Sunday']
# [1] "2015-03-15"
这篇关于如何在R中找到上一个星期日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文