【发布时间】:2021-04-15 19:59:15
【问题描述】:
我正在尝试解析具有两种日期格式的向量,包括日期和不包括日期,因此只有在没有提供日期的情况下,日期才会默认为该月的最后一天。
我让每个组件独立工作,但不知道如何将它们组合在一起。
Reprex 在下面,我想要的输出是"2006-09-30 UTC" "2005-08-23 UTC"。
感谢您的时间和帮助。
library(dplyr)
library(lubridate)
# Parse dates in different formats, and default to last of month if no date specified
lubridate::parse_date_time(
c("September 2006", "August 23, 2005"),
orders = c("my", "mdY")
)
#> [1] "2006-09-01 UTC" "2005-08-23 UTC"
lubridate::my("September 2006") %>%
ceiling_date("month") - 1
#> [1] "2006-09-30"
由reprex package (v0.3.0) 于 2021-04-15 创建
【问题讨论】: