I have a data with column- and row-names that have a string with a number that goes from 1 to 100.
I am using grepl to select names that have a specific number (while ignoring the string). Say I have:
a <- matrix(c(1:16), nrow = 4, byrow = TRUE)
colnames(a) <- c("aaa1", "bbb1", "abc11", "ccc100")
rownames(a) <- c("aaa1", "bbb1", "abc11", "ccc100")
giving matrix a
       aaa1 bbb1 abc11 ccc100
aaa1      1    2     3      4
bbb1      5    6     7      8
abc11     9   10    11     12
ccc100   13   14    15     16
I would like to select the rows and column that include a "1" but nothing else. Like this:
     aaa1 bbb1
aaa1    1    2
bbb1    5    6 
But when I use:
a[grepl("1" , rownames(a)) , grepl("1" , colnames(a))]
I get matrix a again. I tried using "^1" but it of course doesn't find any name that's exactly 1. What can I do to solve this? I appreciate any help.