Genetics
Genetics

Reputation: 301

use subset() in R with changing subset column names

I have some data with column names. I need to subset the column DF.classifications_0.25_0.02_268. However, DF.classifications is a base with the numbers always changing. I have tried grep, names, colnames in the subset() and still getting errors. Any solutions? I really want this to be used in the subset() for various reason.

An example of failed code:

cts.seurat.obj.filtered <- subset(cts.seurat.obj.filtered, colnames([email protected])[6] == "Singlet")


names([email protected])
[1] "orig.ident"                       "nCount_RNA"
[3] "nFeature_RNA"                     "percent.mt"
[5] "pANN_0.25_0.02_268"               "DF.classifications_0.25_0.02_268"

Upvotes: 1

Views: 497

Answers (1)

akrun
akrun

Reputation: 887058

We can select the column only if the 6th column name is 'Singlet'

if( colnames([email protected])[6] == "Singlet")    
 {
   subset(cts.seurat.obj.filtered, select = Singlet)
}

Upvotes: 1

Related Questions