Warm tip: This article is reproduced from serverfault.com, please click

R convert data into a vector

发布于 2021-02-23 14:32:45

I have an object (Seurat object) an I need to get certain data out of it

> sc@misc[["colors"]][["seurat_clusters"]]
          0           1           2           3           4           5           6           7 
"#CC0C00FF" "#5C88DAFF" "#84BD00FF" "#FFCD00FF" "#7C878EFF" "#00B5E2FF" "#00AF66FF" "#CC0C00B2" 

This data is needed as an vector but I don't know how to pull "#CC0C00FF" "#5C88DAFF" etc. out of it.

In order to hand this data to the next function, the result should look like this:

> vec
[1] "#CC0C00FF" "#5C88DAFF" "#84BD00FF"

Thanks in advance!

Questioner
mariusr
Viewed
0
mariusr 2021-02-24 01:02:17

Solved it! I'm pretty disappointed by myself, because I didn't know this function existed:

> as.vector(sc@misc[["colors"]][["seurat_clusters"]])
[1] "#CC0C00FF" "#5C88DAFF" "#84BD00FF" "#FFCD00FF" "#7C878EFF" "#00B5E2FF" "#00AF66FF" "#CC0C00B2"