H C
H C

Reputation: 17

deselect matrix columns using subsed and !grepl functions

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

Upvotes: 0

Views: 18

Answers (1)

H C
H C

Reputation: 17

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.

Upvotes: 0

Related Questions