All.equal () in base R not returning TRUE

I am wondering why it all.equal()does not return TRUE for the following data:

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
+4
source share
1 answer

Just make sure 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)
+5
source

Source: https://habr.com/ru/post/1676700/


All Articles