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

后端 未结 5 854
走了就别回头了
走了就别回头了 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:34

    You can sapply over all the prices and apply the all.equal function to each one, to find the one that is TRUE

    which(sapply(price, all.equal, lookupPrice) == TRUE)
    # [1] 425
    

提交回复
热议问题