我将这个向量放在时间数据框中,格式为小时:分钟,我想将其转换为一天中的分类时间:
time <- c("15:03", "08:01", "11:59", "23:47", "14:20")
df$time <- format(strptime(df$time, tz = "" , format = "%H: %M"), format = "%H: %M")
df <- data.frame(time)
Run Code Online (Sandbox Code Playgroud)
我想我会考虑早上 5 点到 11 点,下午 11 点到 16 点,晚上 16 点到 19 点,以及除此之外的任何时间,直到晚上 5 点。原始数据的时间格式为小时:分钟,使用 strptime()。
我在论坛上发现了一些类似的问题,但我似乎无法调整代码来处理我的数据。