I have matrix g:
> g[1:5,1:5]
rs7510853 rs10154488 rs12159982 rs2844887 rs2844888
NA06985 \"CC\" \"CC\" \"CC\" \
I use "setdiff" as follows:
g[setdiff(rownames(g),remove),]
When working with indexing, you cannot use "negative" character vectors. You can convert to logical with %in%
g[!rownames(g) %in% remove, ]
If you really wanted to use negative-indexing this could be done:
g[-which(rownames(g) %in% remove), ]
... however it has a nasty potential erroneous result that arises when there are not any rownames in the target vector. The result may be no values returned.
You cannot negative index a character vector when indexing. Turn your vector remove
into a boolean. I've defined a function
`%notin%` <- function(x,y) !(x %in% y)
which can then be used as such: g[rownames(g) %notin% remove ,]