我有一個數字矢量如下將數字值日期
aa <- c(1022011, 2022011, 13022011, 23022011) (this vector is just a sample, it is very long)
值都寫在這樣一種方式,首先看重的是天則一個月,然後一年。
什麼我現在做的是
as.Date(as.character(aa), %d%m%Y")
但是,
它造成個位數日的數字的情況下問題(返回NA)。 (即1022011,2022011)。
所以基本上
as.Date("1022011", "%d%m%Y") does not work
但
as.Date("01022011", "%d%m%Y") (pasting '0' ahead of the number) works.
我想避免在這種情況下粘貼 '0'。有沒有其他(直接)替代品將數值同時轉換爲日期?
有一些例子在這裏,你可能會發現有用http://stackoverflow.com/questions/16301204/r-converting-date-and-time-fields-to-posixct-with- hhmmss-format – 2014-11-04 12:31:49
我猜'130222011'是一個錯字?似乎那裏有一個額外的數字。 – jazzurro 2014-11-04 12:35:41
是的。糾正。感謝您指出。 – user3664020 2014-11-04 12:37:54