I have a vector of strings:
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")
If I parse it using parse_date_time
from lubridate
package, it would get different result if I only parse the first 6 strings. Why?
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
There is a function guess_formats
which is so kind to explain which elements match the template. As you can see only the last string does:
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"
I think the rest is obvious.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments