2011-12-06 57 views
7
D <- "06.12.1948"     # which is dd.mm.yyyy 
as.Date(D, "%d.%m.%y")   # convert to date 
[1] "2019-12-06"     # ????  

我錯過了什麼?將字符串轉換爲日期格式:「dd.mm.yyyy」

Sys.getlocale(類別= 「LC_ALL」) [1] 「LC_COLLATE = German_Austria.1252; LC_CTYPE = German_Austria.1252; LC_MONETARY = German_Austria.1252; LC_NUMERIC = C; LC_TIME = German_Austria.1252」

回答

19

格式是區分大小寫的( 「%Y」 是模糊的,依賴於系統的,我相信):

as.Date(D, "%d.%m.%Y") 
[1] "1948-12-06" 

幫助主題?strptime有更多的細節:

‘%y’ Year without century (00-99). On input, values 00 to 68 are 
     prefixed by 20 and 69 to 99 by 19 - that is the behaviour 
     specified by the 2004 and 2008 POSIX standards, but they do 
     also say ‘it is expected that in a future version the default 
     century inferred from a 2-digit year will change’. 
+0

爲了擴大這個,''%y「'是兩位數年份,因此它在1948年的」19「中被讀出。你想''%Y'''。 –

相關問題