由于right
中的默认参数cut
默认设置为TRUE
,我希望通过以下两个cut
注释获得完全相同的结果。为什么不是这样?
> breaks <- as.Date(c("2016-02-05", "2016-02-12", "2016-02-19"))
> d <- as.Date("2016-02-12")
> cut(d, breaks, right=TRUE)
[1] 2016-02-05
Levels: 2016-02-05 2016-02-12
> cut(d, breaks)
[1] 2016-02-12
Levels: 2016-02-05 2016-02-12
但是,当我第一次将Date
个对象转换为数值时,我会得到相同的结果:
> breaks <- as.numeric(as.Date(c("2016-02-05", "2016-02-12", "2016-02-19")))
> d <- as.numeric(as.Date("2016-02-12"))
> cut(d, breaks, right=TRUE)
[1] (16836,16843]
Levels: (16836,16843] (16843,16850]
> cut(d, breaks)
[1] (16836,16843]
Levels: (16836,16843] (16843,16850]
这不是违反直觉吗?