我正在尝试制作一个仅由一小时间隔的时间组成的序列,没有日期。它应该如下所示:
"00:00:00" "1:00:00" "2:00:00" "3:00:00"
我知道这段代码有效:
dat <- seq(
from=as.POSIXct("00:00:00","%H:%M:%S", tz="UTC"),
to=as.POSIXct("23:00:00", "%H:%M:%S", tz="UTC"),
by="hour"
)
这使
[1] "2018-04-10 00:00:00 UTC" "2018-04-10 01:00:00 UTC" "2018-04-10 02:00:00 UTC" "2018-04-10 03:00:00 UTC" "2018-04-10 04:00:00 UTC"
[6] "2018-04-10 05:00:00 UTC" "2018-04-10 06:00:00 UTC" "2018-04-10 07:00:00 UTC" "2018-04-10 08:00:00 UTC" "2018-04-10 09:00:00 UTC"
[11] "2018-04-10 10:00:00 UTC" "2018-04-10 11:00:00 UTC" "2018-04-10 12:00:00 UTC" "2018-04-10 13:00:00 UTC" "2018-04-10 14:00:00 UTC"
[16] "2018-04-10 15:00:00 UTC" "2018-04-10 16:00:00 UTC" "2018-04-10 17:00:00 UTC" "2018-04-10 18:00:00 UTC" "2018-04-10 19:00:00 UTC"
[21] "2018-04-10 20:00:00 UTC" "2018-04-10 21:00:00 UTC" "2018-04-10 22:00:00 UTC" "2018-04-10 23:00:00 UTC"
但这不是我想要的。因此我尝试了
library(chron)
seq(from = times("00:00:00"), to =times("23:00:00"), by="hour")
这给出了一个错误
Error in convert.times(times., fmt) : format h:m:s may be incorrect
In addition: Warning message:
In unpaste(times, sep = fmt$sep, fnames = fmt$periods, nfields = 3) :
wrong number of fields in entry(ies) 1
我现在卡住了,所以我希望有人可以帮助我。当然我可以把它打出来,但我想要一个干净的解决方案。