将字符串转换为日期,格式为:"dd.mm.yyyy"

Kay*_*Kay 9 r date

D <- "06.12.1948"                 # which is dd.mm.yyyy
as.Date(D, "%d.%m.%y")            # convert to date
[1] "2019-12-06"                  # ????    
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

Sys.getlocale(category ="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"

mds*_*ner 23

格式区分大小写("%y"是模糊的,系统相关,我相信):

as.Date(D, "%d.%m.%Y")
[1] "1948-12-06"
Run Code Online (Sandbox Code Playgroud)

帮助主题?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’.
Run Code Online (Sandbox Code Playgroud)


Ron*_*hah 11

为了避免记住日期的格式,我们可以使用打包的解决方案。

1) 与lubridate

lubridate::dmy(D)
#[1] "1948-12-06"
Run Code Online (Sandbox Code Playgroud)

2)使用anytime

anytime::anydate(D)
#[1] "1948-06-12"
Run Code Online (Sandbox Code Playgroud)