I'm trying to extract the indices of a large matrix on the basis of grepping two separate strings.
An example matrix might look like:
a=as.matrix(c("a","b","c"))
a=cbind(a,c("yes", "no", "maybe"))
rownames(a)=c("one", "two","three")
colnames(a)=c("letter", "status")
Both of these work:
grep("letter", colnames(a))
grep("status", colnames(a))
I'd like this to work, but it doesn't:
grep("letter"|"status", colnames(a))
Is the easiest way to collect both greps just concatenating them into a vector, or is there something we can do within the grep function?:
cols_to_get= c(grep("letter", colnames(a)), grep("status", colnames(a)))