Home > Back-end >  use subset() in R with changing subset column names
use subset() in R with changing subset column names

Time:10-05

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"

CodePudding user response:

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)
}
  • Related