# Subsetting a Seurat object based on colnames

I'm trying to subset my seurat object based on colnames. I have gone ahead and labeled each cluster and now I want to subset all the colnames that are in Cancer_human for human_colnames and all the barcodes that are not in Cancer_human for mouse_colnames but get an error.

human_colnames = colnames(scData[,scData$$cell_ann == "Cancer_human"]) mouse_colnames = colnames(scData[,!scData$$cell_ann == "Cancer_human"])

Error in [.Seurat(scData, , scData\$cell_ann == "Cancer_human") : Incorrect number of logical values provided to subset cells

• The code could only make sense if the data is a square, equal number of rows and columns. At the moment you are getting index from row comparison, then using that index to subset columns. Also, please provide a reproducible example data for testing, dput(myData). Aug 17 at 14:44

I don't think it works that way, mmpp. The [ operation needs either a list of names, indexes or a boolean vector for each of the row and column spots to subset along that dimension, and you cannot use a boolean vector based on rows to subset columns (that's what you're doing here). Google how to subset columns in R.