将UnixTime转换为R中的日间隔(早,晚,晚等)

时间:2017-06-01 10:43:16

标签: r unix-timestamp

我有一个带有TIMESTAMP列和Unix时间值的表。我需要将它转换为一天的间隔,如夜晚,早晨,下午,下午,黄昏,傍晚。

data$TIMESTAMP[1]
[1] 1372636858
time <- anytime(1372636858)
> time
[1] "2013-07-01 01:00:58 WEST" 

我在做:

cut(time, breaks= as.POSIXct(paste("2001-01-01",c("00:00:00", "06:00:00", "09:00:00","12:00:00","15:00:00","18:00:00", "20:00:00")),format="%Y-%m-%d %H:%M:%S", tz ="Portugal"),labels=c('night','morning','before_afternoon','afternoon','twilight','evening'))

输出结果为:

[1] <NA>
Levels: night morning before_afternoon afternoon twilight evening

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我会尝试c('night','morning','before_afternoon','afternoon','twilight','evening')[findInt erval(as.POSIXlt(tim e)$ hour, C(0,6,9,15,1 8,20))。 - 尼古拉6月1日11:06