简体   繁体   English

R base中的all.equal()不返回TRUE

[英]all.equal() in R base not returning TRUE

I'm wondering why all.equal() doesn't return TRUE for the following data: 我想知道为什么all.equal()不会为以下数据返回TRUE:

Like.prob = dbinom(x = 0:2, size = 2, prob = .7)
sim.obs   = rbinom(n = 1e6, size = 2, prob = .7)

sim.Like.prob = unname( table(sim.obs) / 1e6 )[1:3]

all.equal(Like.prob, sim.Like.prob, tolerance = .01) ## Here I expect a TRUE

Just ensure that the two elements have the same class before comparing them: 在比较它们之前,只需确保这两个元素具有相同的类:

class(Like.prob)
class(sim.Like.prob)
all.equal(Like.prob, as.numeric(sim.Like.prob), tolerance = .01)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM