为什么在将字符日期转换为日期格式时会引入NAs?

时间:2018-05-04 14:55:39

标签: r date date-conversion

我有一些日期:

      [,1]           
 [1,] "March 4 2018" 
 [2,] "March 11 2018"
 [3,] "March 18 2018"
 [4,] "March 26 2018"
 [5,] "April 2 2018" 
 [6,] "April 9 2018" 
 [7,] "April 16 2018"
 [8,] "April 23 2018"
 [9,] "April 30 2018"
[10,] "March 4 2018" 
[11,] "March 11 2018"
[12,] "March 18 2018"
[13,] "March 26 2018"
[14,] "April 2 2018" 
[15,] "April 9 2018" 
[16,] "April 16 2018"
[17,] "April 23 2018"
[18,] "April 30 2018"

我想将这些格式转换为日期格式(使用anytime),但会产生一些NA值:

[1] NA                        "2018-03-11 01:00:00 GMT" "2018-03-18 01:00:00 GMT" "2018-03-26 01:00:00 BST" NA                       
 [6] NA                        "2018-04-16 01:00:00 BST" "2018-04-23 01:00:00 BST" "2018-04-30 01:00:00 BST" NA                       
[11] "2018-03-11 01:00:00 GMT" "2018-03-18 01:00:00 GMT" "2018-03-26 01:00:00 BST" NA                        NA                       
[16] "2018-04-16 01:00:00 BST" "2018-04-23 01:00:00 BST" "2018-04-30 01:00:00 BST"

这是我使用的命令:

library(anytime)
anytime(df$date)

为什么会发生这种情况?如何纠正?

1 个答案:

答案 0 :(得分:0)

根据人们的建议,{{1}}在这里为我效劳。

谢谢大家。