我想知道是否有人知道可以检测R中日期列格式的任何中断的包或函数,即检测日期向量格式的更改位置,如:
11/2/90
12/2/90
.
.
.
15/Feb/1990
16/Feb/1990
.
.
.
20/February/90
21/February/90
.
.
.
25/2/1990
26/2/1990
Run Code Online (Sandbox Code Playgroud)
你只需要检测休息时间,还是最终想要转换它们?
guess_formats包中的函数lubridate在两种情况下都很有用.从您的数据中查看此示例:
dates = c("11/2/90",
"12/2/90",
"15/Feb/1990",
"16/Feb/1990",
"20/February/90",
"21/February/90",
"25/2/1990",
"26/2/1990")
guess_formats(dates, order="dmy")
dmy dmy dmy dmy dmy dmy dmy dmy
"%d/%m/%y" "%d/%m/%y" "%d/%b/%Y" "%d/%b/%Y" "%d/%B/%y" "%d/%B/%y" "%d/%m/%Y" "%d/%m/%Y"
dates2 = as.Date(dates, format=guess_formats(dates, order="dmy")
dates2
[1] "1990-02-11" "1990-02-12" "1990-02-15" "1990-02-16" "1990-02-20" "1990-02-21" "1990-02-25" "1990-02-26"
Run Code Online (Sandbox Code Playgroud)