我有这个染色体编号注释列表。我将从每个字符串中提取第一个字符
[[1]]
[1] "KQ415812.1"
[[2]]
[1] "KQ415813.1" "KQ415813.1" "KQ415813.1" "KQ415813.1" "KQ415813.1" "KQ415813.1" "KQ415813.1"
[12] "KQ415813.1" "KQ415813.1" "KQ415813.1" "KQ415813.1" "KQ415813.1" "KQ415813.1" "KQ415813.1"
[[3]]
[1] "KQ415814.1" "KQ415814.1" "KQ415814.1" "KQ415814.1" "KQ415814.1" "KQ415813.1"
[12] "KQ415814.1"
我会得到这个结果,因为每个字符串中的字符都是重复的,所以我只需要显示一次
[[1]]
[1] "KQ415812.1"
[[2]]
[1] "KQ415813.1"
[12] "KQ415813.1"
[[3]]
[1] "DKQ415814.1"
[12] "DKQ415814.1"
有帮助吗?谢谢
答案 0 :(得分:1)
purrr
解决方案:
library(purrr)
yours_list %>%
map(~.x[1])
答案 1 :(得分:0)
遍历list
(lapply
),创建一个逻辑表达式以获取第一个元素
lapply(lst1, function(x) x[!duplicated(x)])