I've come across the same error which seems to be a common issue when using the
subset() function with Seurat objects. Sometimes, I encountered the same error and couldn't figure out the reason behind it, checking the variable's names was not a remedy in my case as I specified the exact same name for subsetting as to what I could see in my object metadata. However, I found a workaround to subset cells in a Seurat object using a different approach.
Instead of using
subset(), you can try the following:
seurat_obj_subset <- seurat_obj[, <condition to be met>]
For example, if you want to subset a Seurat object called 'pbmc' based on conditions like having more than 1000 features and more than 4000 counts, you can use the following code:
pbmc = pbmc[, pbmc$nFeature > 1000 & pbmc$nCount > 4000]