R How to use which() with floating point values?

后端 未结 5 851
走了就别回头了
走了就别回头了 2020-12-11 20:11

I have run into the same problem as described at R which () function returns integer(0)

price = seq(4,7, by=0.0025)
allPrices = as.data.frame(price)
lookupP         


        
5条回答
  •  庸人自扰
    2020-12-11 20:50

    There is a function near in dplyr:

    near(x, y, tol = .Machine$double.eps^0.5)
    

    For this case, you can try:

    which(near(allPrices$price, lookupPrice))
    #[1] 425
    

提交回复
热议问题