【问题标题】:Filtering for close dates in the next 30 days based on current date in R根据 R 中的当前日期过滤未来 30 天内的关闭日期
【发布时间】:2022-02-01 17:02:59
【问题描述】:

我在根据 R 中的今天日期仅过滤未来 30 天内的日期时遇到问题。我要过滤的结束日期列已设置为日期类型,格式为 Year-Month-Day(2022 -06-22)。

我希望能够使用截止日期为今天之后 30 天的记录。

x_data %>% filter(CloseDate > today())

这仅显示大于今天日期的任何内容,但我希望它仅针对从今天起接下来的 30 天。

谢谢!

【问题讨论】:

    标签: r date


    【解决方案1】:

    您可以简单地将第二个条件添加到您的 dplyr::filter() 喜欢

    x_date %>% filter(CloseDate > today() & CloseDate <= today() + 30)
    

    【讨论】:

    • @tivd- 谢谢! Curveball-我刚刚注意到过去的“关闭日期”有一些交易。是否也可以有一个“安全捕获”的回顾期?意思是,不仅提前 30 天,而且还提前 30 天,这样我就可以查看哪些交易没有达到目标?
    • @Edmonds15 是的,如果您使用filter(CloseDate &gt;= today() - 30 &amp; CloseDate &lt;= today() + 30),您将获得完整的 60 天期限。
    猜你喜欢
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 2018-06-11
    • 2020-05-25
    • 2020-01-18
    相关资源
    最近更新 更多