如何从列表列表中提取元素 [英] How to extract elements from list of lists
本文介绍了如何从列表列表中提取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 R 的新手.我在 R 中有一个列表 t1
看起来像
I am a newbie to R. I have a list t1
in R which looks like
[[1]]
[[1]][[1]]
[1] "a" "control"
[[2]]
[[2]][[1]]
[1] "a" "disease1"
[[3]]
[[3]][[1]]
[1] "a" "disease2"
[[4]]
[[4]][[1]]
[1] "b" "control"
[[5]]
[[5]][[1]]
[1] "b" "disease1"
[[6]]
[[6]][[1]]
[1] "b" "disease2"
我需要将第一个元素的唯一列表放入向量中,即 ["a", "b"] 来自该向量 t1
.我怎样才能做到这一点?
I need to get a unique list of first elements into a vector i.e ["a", "b"] from this vector t1
. How can I do this?
推荐答案
rapply
提供了另一种选择:
unique(rapply(t1, function(x) head(x, 1)))
这篇关于如何从列表列表中提取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文