在 R 中使用 lubridate 包对相同日期字符串的不同结果

Different results for same date string using lubridate package in R

我有一个字符串向量:

str <- c("01-", "01-just researching", "01-1-3 months", "01-immediately", "01-4-6 months", "01-more than 12 months", "01-7-12 months")

如果我使用 lubridate 包中的 parse_date_time 解析它,如果我只解析前 6 个字符串,它会得到不同的结果。为什么?

parse_date_time(str, "dmy")
[1] NA               NA               "2003-01-01 UTC" NA               "2006-04-01 UTC"
[6] NA               "2012-07-01 UTC"

parse_date_time(str[1:6], "dmy")
[1] NA NA NA NA NA NA

有一个函数guess_formats很好地解释了哪些元素与模板匹配。如您所见,只有最后一个字符串:

guess_formats(str, "dmy", print_matches = TRUE)

#                               dmy              
# [1,] "01-"                    ""               
# [2,] "01-just researching"    ""               
# [3,] "01-1-3 months"          ""               
# [4,] "01-immediately"         ""               
# [5,] "01-4-6 months"          ""               
# [6,] "01-more than 12 months" ""               
# [7,] "01-7-12 months"         "%d-%m-%y months"

我想剩下的就很明显了。