2011-12-06 2 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 ''는 2 자리 연도이므로 1948 년에 "19"로 읽습니다.' "% Y"'를 원합니다. –

관련 문제