Remove values in vector from double variable in R

会有一股神秘感。 提交于 2019-12-12 01:42:50

问题


I have a variable of type double X: 1.5 1.3 0.6 1.8 2.9 2.1 1.5 1.4 5.8 0.0 and a vector V: c(0.6,2.9). I want to remove the values in V from X

 test<-X[!X %in% V]

The values are not removed from test:

test
 [1] 1.5 1.3 0.6 1.8 2.9 2.1 1.5 1.4 5.8 0.0`

I tried the following:

are.equal <- function(x, y, eps = .Machine$double.eps^0.5) abs(x - y) < eps
    test=X[!(are.equal(X,0.6))]

0.6 were removed.. I could have something odd in my data or my system. Any idea?

来源:https://stackoverflow.com/questions/31331217/remove-values-in-vector-from-double-variable-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!