2011-12-06 15 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 "'が必要です。 –

関連する問題