Subsetting a matrix by row.names

后端 未结 3 986
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 01:49

I have a matrix with the following row.names:

\"X1\"   \"X5\"   \"X33\"  \"X37\"  \"X52\"  \"X566\"

Now I want to select only the rows whic

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 02:24

    Just in case someone's include_list is class list (rather than vector), then this is modification of Rich Scriven's answer that works in such case based on this. unlist() should be added:

    m <- matrix(1:30, 6, 5)
    rownames(m) <- c("X1", "X5", "X33", "X37", "X52", "X566")
    include_list <- list("X1", "X5", "X33")
    
    
    m[unlist(include_list), ]
    

提交回复
热议问题