gpt4 book ai didi

r - 以 30 分钟间隔创建时间序列

转载 作者:行者123 更新时间:2023-12-03 09:18:28 26 4
gpt4 key购买 nike

我正在尝试创建一个间隔为 30 分钟的时间序列。我使用了以下命令,还显示了输出:

ts = seq(as.POSIXct("2009-01-01 00:00"), as.POSIXct("2014-12-31 23:30"),by = "hour") 

"2010-02-21 12:00:00 EST" "2010-02-21 13:00:00 EST" "2010-02-21 14:00:00 EST"

当我将其更改为 by ="min" 时,它会更改为每分钟。

如何创建每 30 分钟间隔的时间序列?

最佳答案

您可以在 by 参数中指定分钟,并传递时区“UTC”,正如 Adrian 指出的那样。有关指定为字符串的 by 参数的更多详细信息,请检查 ?seq.POSIXt:

A character string, containing one of "sec", "min", "hour", "day", "DSTday", "week", "month", "quarter" or "year". This can optionally be preceded by a (positive or negative) integer and a space, or followed by "s".

ts <- seq(as.POSIXct("2017-01-01", tz = "UTC"),
as.POSIXct("2017-01-02", tz = "UTC"),
by = "30 min")
head(ts)

输出

[1] "2017-01-01 00:00:00 UTC"
[2] "2017-01-01 00:30:00 UTC"
[3] "2017-01-01 01:00:00 UTC"
[4] "2017-01-01 01:30:00 UTC"
[5] "2017-01-01 02:00:00 UTC"
[6] "2017-01-01 02:30:00 UTC"

关于r - 以 30 分钟间隔创建时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35296749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com