Remove values in vector from double variable in R

2019-09-02 03:59发布

问题:

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?