r-分析异构日期列中的日期

  • 本文关键字:日期 异构 r date lubridate
  • 更新时间 :
  • 英文 :


我有一个奇怪的日期列,因为月、日和年之间没有分隔符。这些日期之间的主要区别是缺少月份/日期中的0。

日期日期908981998-09-08911981998-11-08<100298><10599>316991999-03-16

我们可以根据字符数插入0,然后应用mdy

library(lubridate)
mdy(sub("00$", "20", sub("^(.)(..)(..)$", "0\1\2\3", dates$Dates)))

-输出

[1] "2001-10-30" "2020-04-14" "2001-09-05" "2020-09-22" "1999-10-29" "2001-10-24" "2020-01-28" "2020-09-19" "2001-11-19" "1999-08-31" "2020-03-17"
[12] "2020-01-14" "2020-11-22" "1999-09-10" "1999-05-21" "2001-10-11" "1999-08-19" "2001-05-04" "2001-09-27" "2001-08-08" "2001-08-16" "2020-11-16"
[23] "1999-09-07" "1998-11-09" "2001-04-20" "2001-05-18" "1998-12-14" "1999-10-08" "1999-09-14" "1998-09-25" "2020-05-19" "1999-11-24" "2020-06-30"
[34] "2001-11-06" "1999-03-16" "1998-10-16" "1998-11-23" "2001-02-02" "2001-02-23" "1999-01-05" "2001-07-11" "1998-12-28" "1999-09-28" "1999-07-27"
[45] "2020-08-04" "2020-02-11" "2020-07-28" "1999-01-20" "2020-08-11" "1999-10-15" "1999-09-03" "2020-05-04" "2020-12-08" "1998-09-18" "1999-06-02"
[56] "2001-06-27" "1998-10-02" "2001-07-25" "2020-01-03" "2020-09-26" "2001-03-16" "2020-02-18" "1999-03-09" "2020-03-02" "1999-09-24" "2020-06-02"
[67] "2002-01-09" "2020-06-23" "2020-08-18" "2001-06-13" "1998-09-29" "1999-04-21" "2020-07-14" "2002-01-29" "2002-03-19" "1999-10-19" "1999-06-21"
[78] "1999-04-30" "1998-11-16" "2020-07-21" "1999-02-23" "2002-04-04" "2001-08-23" "1998-11-03" "1998-10-27" "2020-06-09" "2020-10-03" "1998-10-20"
[89] "2002-02-20" "2020-10-27" "2001-08-30" "1999-08-11"

相关内容

  • 没有找到相关文章

最新更新