简体   繁体   中英

How to properly compare numbers in scientific notation using R?

I was reading the following tutorial for testing proportions in two populations. After running

prop.test(x=c(342,290), n=c(400,400))

I received a p-value of 9.558674e-06, which the tutorial says is greater than the alpha level of.05. I assumed this was a typo, and was just comparing the p-value to its value in decimal notation, 0.000009558674, but received "False". I even turned off scientific notation using

options(scipen=999)

and when printing out the p-value from the object returned by prop.test, I still receive "False" when comparing the p-value to 0.000009558674 for equality, it recognizes the p-value as lesser than. Why is this the case?

You may want to consider using the all.equal() function. The tolerance between the values can be set with the tolerance argument.

isTRUE(all.equal(2, 2.00000001))
##  [1] TRUE
isTRUE(all.equal(2, 2.00000001, tolerance = 0.0000000001))
##  [1] FALSE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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