I want to delete a row of matrix x indexed by vector k such as
x = matrix(1:10, 5, 2)
k = rep(1, 5)
# my attempt:
index = which(k == 0)
y = x[-index, ]
# [,1] [,2]
Here, no rows meet my condition for dropping, k == 0, so index will return the empty vector, integer(0). Therefore, x[-index, ] will return a matrix with no lines instead of remaining itself.
I don't know how to handle this, please someone could help me on this?