我观察此:数据一致性:表VS ==
> class(x)
[1] "numeric"
> str(x)
num [1:2500] 1 1 1 1 1 1 1 1 1 1 ...
> table(x)
1
2500
> table(x == 1)
FALSE TRUE
299 2201
> all.equal(x, rep(1,length(x)))
[1] TRUE
> dput(x)
c(1, ..... 1) # all ones
,这怎么可能?我了解floating point numbers should not be compared using ==
in general,但不应该table
与==
一致吗?
PS。显然,table
与all.equal
一致,而不是与==
一致,因为它首先将其参数转换为因子(即字符串)。
PPS。 table(x-1)
显示非0值。
对我来说它工作正常 –
@sds不确定你的评论意味着什么。怎么样一个可重复的例子? – Frank
你可以使用'dput' – akrun