Delete custom additional column from Seurat metadata
2
1
Entering edit mode
5.8 years ago
yuhongruoyi ▴ 10

I add some columns of custom metadata by using the Seurat v3.X command object$name <- vector, but I can't delete these columns, such as "time", "hours". I try many many ways, like subset, subsetdata, and test.tc11$hours <- NULL, all them didn't work.

Can you help me?

> test.tc11$hours <- rep("E14",7303)
> tail(x = test.tc11[[]])

                      orig.ident nCount_RNA nFeature_RNA percent.mito RNA_snn_res.0.8 letter.idents time DAY hours
A_TTTGTCACATTGGTAC SeuratProject       3987         1775            0               7             H  E11 E14   E14
A_TTTGTCAGTAAGTGGC SeuratProject       4299         1992            0               7             H  E11 E14   E14
A_TTTGTCAGTAGGACAC SeuratProject       6994         2448            0               0             A  E11 E14   E14
A_TTTGTCAGTAGGCATG SeuratProject       7906         2588            0               4             E  E11 E14   E14
A_TTTGTCAGTCTCATCC SeuratProject      24778         5035            0               8             I  E11 E14   E14
A_TTTGTCAGTTCTGTTT SeuratProject       8209         2628            0               2             C  E11 E14   E14
RNA-Seq R r Seurat • 5.0k views
ADD COMMENT
0
Entering edit mode
df <- df[,-c($column_number)] ?
ADD REPLY
1
Entering edit mode
5.8 years ago

this worked for me:

> test_seur$testing <- "testing"
> str(test_seur@meta.data)
'data.frame':   979 obs. of  4 variables:
 $ orig.ident  : chr  "AdultHS" "AdultHS" "AdultHS" "AdultHS" ...
 $ nCount_RNA  : num  NA NA NA NA NA NA NA NA NA NA ...
 $ nFeature_RNA: int  NA NA NA NA NA NA NA NA NA NA ...
 $ testing     : chr  "testing" "testing" "testing" "testing" ...
> test_seur@meta.data$testing <- NULL
> str(test_seur@meta.data)
'data.frame':   979 obs. of  3 variables:
 $ orig.ident  : chr  "AdultHS" "AdultHS" "AdultHS" "AdultHS" ...
 $ nCount_RNA  : num  NA NA NA NA NA NA NA NA NA NA ...
 $ nFeature_RNA: int  NA NA NA NA NA NA NA NA NA NA ...
ADD COMMENT
0
Entering edit mode
5.8 years ago
zx8754 12k

If Seurat output object class is a data.frame then any of the below should work:

# check class
class(mtcars)
# [1] "data.frame"

# assign NULL
mtcars$cyl <- NULL

# remove by match on name
mtcars <- mtcars[, -match("cyl", colnames(mtcars)) ]

# remove by index
mtcars <- mtcars[, -2 ]

See SO posts for alternatives here and here.

Check the output of str(mydata), class(mydata), and provide reproducible example: dput(head(mydata)).

ADD COMMENT

Login before adding your answer.

Traffic: 1753 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6