有人能给我解释一下为什么下面的POSIXct时间元素不匹配吗?
我最终try 将向量time
中的日期时间值与向量datetime
中的日期时间值进行匹配.我简化了该示例,使所有内容都是相同的日期,只有小时值不同.在本例中,我可以使用match
来查找datetime
中每个time
的索引位置.然而,如果我需要将我的约会时间舍入到time
到最接近的小时,这里给出的roundtime
突然匹配失败?但是time==roundtime
呢?我错过了什么吗?
datetime <- as.POSIXct("2020-01-01 15:00:00",tz="UTC") + (0:10) * 3600
time <- as.POSIXct(c("2020-01-01 15:00:00", "2020-01-01 16:00:00", "2020-01-01 21:00:00"),tz='UTC')
roundtime<-round(time,units="hours")
time %in% datetime # gives TRUES
time %in% roundtime # give FALSES?
time == roundtime # gives TRUES
match(time, datetime) # returns matches
match(time, roundtime) # No matches?
match(roundtime, datetime) # no matches?