R 语言生成时间序列

函数:seq.Date、seq.POSIXt


1. seq.Date

以天为间隔生成时间序列:

temp <- seq.Date(from = as.Date("2018/01/01",format = "%Y/%m/%d"), by = "day", length.out = 365)

会生成Date格式的365个时间戳


以月为间隔

temp <- seq.Date(from = as.Date("2018/01/01",format = "%Y/%m/%d"), by = "month", length.out = 3)

> temp

[1] "1948-01-01" "1948-02-01" "1948-03-01"


by的参数共有:“day”, “week”, “month”,“quarter”, “year”


2. seq.POSIXt

生成date-time格式的时间序列。

以小时为间隔:

temp <- seq.POSIXt(from = as.POSIXct("2199-08-02 05:00:00"), to = as.POSIXct("2199-08-02 10:00:00 CST"), by = 'hour')

> temp
[1] "2199-08-02 05:00:00 CST" "2199-08-02 06:00:00 CST" "2199-08-02 07:00:00 CST"

[4] "2199-08-02 08:00:00 CST" "2199-08-02 09:00:00 CST" "2199-08-02 10:00:00 CST"


 by的参数共有:“sec”, “min”, “hour”, “day”, “DSTday”, “week”, “month”, “quarter”, “year”


你可能感兴趣的:(R)