我将时间视为完整日期时间并将它们保持为该格式的另一种方法:
arrivalString <- c("00:30", "16:45", "14:59")
arrival <- strptime(arrivalString, format = "%H:%M")
names <- c("Ron", "John", "Sam")
df <- data.frame(names, arrival)
slotbegin <- as.POSIXlt(df$arrival)
slotbegin$min <-rep(0, length(slotbegin))
df <- cbind(df, slotbegin)
slotend <- as.POSIXlt(df$arrival)
slotend$min <- rep(0, length(slotend))
slotend$hour <- slotend$hour + 1
df <- cbind(df, slotend)
输出:
names arrival slotbegin slotend
1 Ron 2013-10-09 00:30:00 2013-10-09 00:00:00 2013-10-09 01:00:00
2 John 2013-10-09 16:45:00 2013-10-09 16:00:00 2013-10-09 17:00:00
3 Sam 2013-10-09 14:59:00 2013-10-09 14:00:00 2013-10-09 15:00:00