Skip to Content

Complement of empty index vector is empty index vector

I am removing values from a vector by using - (minus sign) in front of the index vector. Like this:

scores <- scores[]

Sometimes vector is empty, that is N/A. So the scores vector should then remain unchanged. However, I am getting empty scores vector when is empty.


x <- c(1, 2, 3);
y <- c(4, 5, 6); <- which(y < x); # will return empty vector
y <- y[]; # returns empty y vector, but I want y stay untouched

I could code an if statement checking whether is empty, but I am wondering if there is a simpler way?