擷取 datetime 的各部分

在 R 中處理日期與時間

Charlotte Wickham

Instructor

擷取 datetime 的各部分

x <- ymd("2013-02-23")
year(x)
2013
month(x)
2
day(x)
23
在 R 中處理日期與時間

擷取 datetime 的各部分

函式 取得內容
year() 年(含世紀)
month() 月(1-12)
day() 日(1-31)
hour() 時(0-23)
min() 分(0-59)
second() 秒(0-59)
wday() 星期(1-7)
yday() 年內日次,又稱 Julian day(1-366)
tz() 時區
在 R 中處理日期與時間

設定 datetime 的各部分

x
"2013-02-23"
year(x) <- 2017x
"2017-02-23"
在 R 中處理日期與時間

其他實用函式

函式 取得內容
leap_year() 是否閏年(TRUEFALSE
am() 是否上午(TRUEFALSE
pm() 是否下午(TRUEFALSE
dst() 是否日光節約時間期間(TRUEFALSE
quarter() 季度(1-4)
semester() 上下半年(1-2)
在 R 中處理日期與時間

一起來練習吧!

在 R 中處理日期與時間

Preparing Video For Download...