Addmetadata to seurat obj
0
0
Entering edit mode
7 months ago
synat.keam ▴ 100

Dear all,

It is a bit of coding issue. I have Seurat obj seurat.obj.T and in the metadata, a column type contains three levels of arthritis " First arthritis", "Second arthritis" and "Osteoarthritis". I would like to create a another column called group based on the value of the type column by naming First arthritis" to ICI-arthritis and Second Arthritis to ICI-arthritis and Osteoarthritis still = Osteoarthritis. I tried the following codes, but error twice. Could you help check!

seurat.obj.T <- AddMetaData(object = seurat.obj.T, metadata = "group", data = ifelse(seurat_obj@meta.data$type %in% c("First arthritis", "Second arthritis"), "ICI-arthritis", "Osteoarthritis"))

or

seurat.obj.T$group <- ifelse(seurat.obj.T$type %in% c("First arthritis", "Second arthritis"), "ICI-arthritis", "Osteoarthritis")
seurat.obj.T <- AddMetaData(object = seurat.obj.T, metadata = "group")

Thanks in advance.

Kind Regards

seurat • 515 views
ADD COMMENT
2
Entering edit mode

You can do something like below:-

seurat.obj.T@meta.data$group[which(seurat.obj.T@meta.data$type == "First arthritis")] <- "ICI-arthritis"
seurat.obj.T@meta.data$group[which(seurat.obj.T@meta.data$type == "Second Arthritis")] <- "ICI-arthritis"
seurat.obj.T@meta.data$group[which(seurat.obj.T@meta.data$type == "Osteoarthritis")] <- "Osteoarthritis"
ADD REPLY
0
Entering edit mode

Thanks you! Regards

ADD REPLY
0
Entering edit mode

You should include, or specify, the errors that you are getting.

ADD REPLY
0
Entering edit mode

I fixed it. in case anyone faced the same issue.

seurat.obj.T@meta.data$group <- ifelse(seurat.obj.T@meta.data$type %in% c("First arthritis", "Second arthritis"), "ICI-arthritis", "Osteoarthritis")
ADD REPLY

Login before adding your answer.

Traffic: 2169 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