How to remove rows of a matrix by row name, rather than numerical index?

后端 未结 3 2187
渐次进展
渐次进展 2020-12-02 23:07

I have matrix g:

> g[1:5,1:5]
        rs7510853 rs10154488 rs12159982 rs2844887 rs2844888
NA06985 \"CC\"      \"CC\"       \"CC\"       \         


        
3条回答
  •  有刺的猬
    2020-12-02 23:32

    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.

提交回复
热议问题