在Gnu R:
which(seq(0, 1600, 0.05) == 0.3) returns
integer(0)
但是这个:
which(round(seq(0, 1600, 0.05),2) == 0.3) returns
[1] 7
seq()
功能会怎样?
答案 0 :(得分:5)
这基本上是R FAQ 7.31关于浮标之间的比较 - 导致着名的“每个计算机科学家应该知道浮点数”。
简而言之,使用identical()
和其他辅助函数来比较相对于小值\ epsilon,因为浮点类型不能完全相等。