deselect matrix columns using subsed and !grepl functions

17 Views Asked by At

I have a single cell RNA sequencing matrix 'dta' with some cells named with KK00 (KK00.xx). I would like to deselect all these cells. So I wrote dta.s <-subset(dta, !grepl('KK00',colnames(dta)))

It didn't give error but it seems KK00.xx cells are still there when I check by table(sapply(strsplit(colnames(dta.s), "\\."), function(x) {x[1]})).

Can someone help?

Best

1

There are 1 best solutions below

0
H C On

I've solved the problem.

I changed this

dta.s <-subset(dta, !grepl('KK00',colnames(dta)))

to this

dta <- dta[,!grepl('KK00.', colnames(dta))]

Now, it works.