日期入門

在 R 中處理日期與時間

Charlotte Wickham

Instructor

日期

各地日期格式不同

27th Feb 2013

  • 紐西蘭:27/2/2013
  • 美國:2/27/2013
在 R 中處理日期與時間

全球通用的數字日期格式

1 https://xkcd.com/1179/
在 R 中處理日期與時間

ISO 8601 YYYY-MM-DD

  • 從最大到最小時間單位排序
  • 各部分位數固定,需以前導零補齊
  • 電腦可不加分隔符,或日期用 - 分隔
  • 1st of January 2011 -> 2011-01-01
在 R 中處理日期與時間

R 中的日期

2003-02-27
1974
"2003-02-27"
"2003-02-27"
str("2003-02-27")
chr "2003-02-27"
as.Date("2003-02-27")
"2003-02-27"
str(as.Date("2003-02-27"))
Date[1:1], format: "2003-02-27"
  • 匯入日期的套件:readranytime
在 R 中處理日期與時間

一起來練習吧!

在 R 中處理日期與時間

Preparing Video For Download...