简体   繁体   中英

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(cts.seurat.obj.filtered@meta.data)[6] == "Singlet")


names(cts.seurat.obj@meta.data)
[1] "orig.ident"                       "nCount_RNA"
[3] "nFeature_RNA"                     "percent.mt"
[5] "pANN_0.25_0.02_268"               "DF.classifications_0.25_0.02_268"

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM