gpt4 book ai didi

r - 检测日期列格式的中断/更改

转载 作者:行者123 更新时间:2023-12-04 11:18:44 29 4
gpt4 key购买 nike

我想知道是否有人知道可以检测 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

最佳答案

您是只需要检测中断还是最终也想转换这些中断?

lubridate 包中的guess_formats 函数在这两种情况下都很有用。从您的数据中查看此示例:

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"

关于r - 检测日期列格式的中断/更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24158049/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com