简体   繁体   中英

Concatenate list of lists in R

I have a list TF2Gene[1326] which looks like

view(TF2Gene)

structure(list(Sp1=c("a","b","c"),p53=c("x","y","z"),Elk1=c("1","2","3"),...))

So its basically a list of 1326 lists.

Now I want to concatenate the values of these lists in 1 so that I can find the unique members. What I am doing is:

cols <- unique(unlist(TF2Gene))    

Is this correct?

Yes, that is the correct way to do it. On the example above the result would be a vector like:

c("a", "b", "c", "x", "y", "z", "1", "2", "3")

That's only going to work if your lists have atomic elements. Mine usually don't. Try this instead.

do.call(c, list (list( 3,4,5 ) , list( "a","b" )))
[[1]]
[1] 3

[[2]]
[1] 4

[[3]]
[1] 5

[[4]]
[1] "a"

[[5]]
[1] "b"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM