Entering edit mode
3 months ago
Varun Gupta
★
1.3k
I Have 2 seurat objects obj1 and obj2. Both the objects have Barcode column in it, but obj2 has condition_cluster column as well. I want to add condition_cluster column in the metadata of obj1 based on Barcode column. I am using merge function this way:
obj1@metadata <- merge(obj1@meta.data, obj2@meta.data[,c("Barcode","condition_cluster")], by = "Barcode", all.x = TRUE)
I loose the rownames info as well as my Dimplot gives error with out of range values which should not be the case. What am I doing wrong?
When you use the merge function to combine metadata from two Seurat objects, it can lead to loss of row names and may create mismatches in your data if not handled properly. The merge function typically returns a data frame without retaining the row names from the original Seurat objects. Instead of directly assigning the result of the merge function to obj1@metadata, you should merge the metadata and then assign it back to obj1@meta.data, while ensuring to keep the row names. You can do the following: