我想代表24小时的时间间隔10分钟,从凌晨4:00开始,到凌晨4:00结束(不包括4:10;4:20;4:30 )。在我使用Po-6 10编写的代码之上,每小时表示--我如何在10分钟间隔内表示时间?
谢谢
z<-c("04:00:00")
j<-0
time_interval<-NULL
for (i in 1:25) #24 denotes interval of each hour plus one for 4:00 AM again
{
time_interval[i]<-as.POSIXct(z,format="%H:%M:%S")+j
j<-j+60*60 # denotes number of seconds in each hour
}
time_interval<-as.POSIXct(time_interval,origin = "1966-01-01")`enter code here`发布于 2018-11-01 20:24:12
下面只使用基R,并做您想做的事。
z <- "04:00:00"
start <- paste(Sys.Date(), z)
end <- paste(Sys.Date() + 1, z)
w <- seq(as.POSIXct(start), as.POSIXct(end), by = "10 mins")
time_interval <- format(w, format = "%H:%M:%S")
head(time_interval, 10)
# [1] "04:00:00" "04:10:00" "04:20:00" "04:30:00" "04:40:00"
# [6] "04:50:00" "05:00:00" "05:10:00" "05:20:00" "05:30:00"https://stackoverflow.com/questions/53108454
复制相似问题