I have been trying to subset a matrix where rownames are in this format - "chr8:56979853-56987069_RPS20_ENSG00000008988.5"
And I tried to subset like so;
include_list <- c("RPS20", "VIL1", "KRT20", "CLDN7")
goi <- subset(mat2, rownames(mat2) %like% include_list)
However it errs as the pattern takes only the first element. Is there a way to subset by a list of elements. Any help is appreciated.
out <- c()
for (x in include_list) {
check_each <- rownames(mat2)[rownames(mat2) %like% include_list]
out <- c(out, check_each)
}
goi <- subset(mat2, rownames(mat2) %in% out)
note that %like% is from the DescTools package, or you can use base R:
out <- c()
for (x in include_list) {
check_each <- rownames(mat2)[grepl(x, rownames(mat2))]
out <- c(out, check_each)
}
goi <- subset(mat2, rownames(mat2) %in% out)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.