根据元素获取匹配并订购两个列表' r中的名称
我需要匹配两个列表,list_1
和list_2
,还可以根据元素的名称按顺序获取它们。实际上,我想删除元素,这些元素在两个列表之间并不常见。我不想考虑其嵌套列表中的任何区别。所需的输出是两个列表,包括两个列表中存在的唯一元素。 两者都有相同的结构。
list_1 <- list(ENSG0000014 = structure(list(name = c("E-1122O", "E-11EM3",
"E-11EMC", "E-1442O", "E-1132O"), ENSG = c("ENSG0000014", "ENSG0000014",
"ENSG0000014", "ENSG0000014", "ENSG0000014"), expr = c(" 9.940670e-02",
" 1.289670e-01", "-7.394904e-03", " 9.940670e-02", " 9.940670e-02"
), `1_43222779_A_G_b37` = c("1", "1", "2", "1", "0"), `1_43222856_A_G_b37` = c("0",
"0", "0", "1", "1"), `1_43223126_C_T_b37` = c("0", "1", "0",
"1", "2"), `1_43223317_T_C_b37` = c("1", "0", "0", "2", "1")), row.names = c(NA,
-5L), class = c("tbl_df", "tbl", "data.frame")), ENSG0000015 = structure(list(
name = c("E-1122O", "E-11EM3", "E-11EMC", "E-1442O", "E-1132O"
), ENSG = c("ENSG0000015", "ENSG0000015", "ENSG0000015",
"ENSG0000015", "ENSG0000015"), expr = c(" 9.940670e-02",
" 1.289670e-01", "-7.394904e-03", " 9.940670e-02", " 1.289670e-01"
), `1_43222779_A_G_b37` = c("0", "1", "0", "1", "2"), `1_43222856_A_G_b37` = c("1",
"1", "2", "1", "0")), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame")))
list_2 <- list(ENSG0000014 = structure(list(name = c("E-1122O", "E-11EM3",
"E-11EMC", "E-1442O", "E-1132O"), ENSG = c("ENSG0000014", "ENSG0000014",
"ENSG0000014", "ENSG0000014", "ENSG0000014"), expr = c(" 9.940670e-02",
" 1.289670e-01", "-7.394904e-03", " 9.940670e-02", " 9.940670e-02"
), `1_43222779_A_G_b37` = c("1", "1", "2", "1", "0"), `1_43222856_A_G_b37` = c("0",
"0", "0", "1", "1"), `1_43223126_C_T_b37` = c("0", "1", "0",
"1", "2"), `1_43223317_T_C_b37` = c("1", "0", "0", "2", "1")), row.names = c(NA,
-5L), class = c("tbl_df", "tbl", "data.frame")), ENSG0000016 = structure(list(
name = c("E-1122O", "E-11EM3", "E-11EMC", "E-1442O", "E-1132O"
), ENSG = c("ENSG0000015", "ENSG0000015", "ENSG0000015",
"ENSG0000015", "ENSG0000015"), expr = c(" 9.940670e-02",
" 1.289670e-01", "-7.394904e-03", " 9.940670e-02", " 1.289670e-01"
), `1_43222779_A_G_b37` = c("0", "1", "0", "1", "2"), `1_43222856_A_G_b37` = c("1",
"1", "2", "1", "0")), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame")))
I need to get matched the two lists, list_1
and list_2
and also get them in order based on elements' name. In fact, I want to remove the elements, those are not common between two lists. I do not want to consider any difference in their nested lists. The desired outputs are two lists including the only elements whose exist in both lists.
Both have same structure.
list_1 <- list(ENSG0000014 = structure(list(name = c("E-1122O", "E-11EM3",
"E-11EMC", "E-1442O", "E-1132O"), ENSG = c("ENSG0000014", "ENSG0000014",
"ENSG0000014", "ENSG0000014", "ENSG0000014"), expr = c(" 9.940670e-02",
" 1.289670e-01", "-7.394904e-03", " 9.940670e-02", " 9.940670e-02"
), `1_43222779_A_G_b37` = c("1", "1", "2", "1", "0"), `1_43222856_A_G_b37` = c("0",
"0", "0", "1", "1"), `1_43223126_C_T_b37` = c("0", "1", "0",
"1", "2"), `1_43223317_T_C_b37` = c("1", "0", "0", "2", "1")), row.names = c(NA,
-5L), class = c("tbl_df", "tbl", "data.frame")), ENSG0000015 = structure(list(
name = c("E-1122O", "E-11EM3", "E-11EMC", "E-1442O", "E-1132O"
), ENSG = c("ENSG0000015", "ENSG0000015", "ENSG0000015",
"ENSG0000015", "ENSG0000015"), expr = c(" 9.940670e-02",
" 1.289670e-01", "-7.394904e-03", " 9.940670e-02", " 1.289670e-01"
), `1_43222779_A_G_b37` = c("0", "1", "0", "1", "2"), `1_43222856_A_G_b37` = c("1",
"1", "2", "1", "0")), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame")))
list_2 <- list(ENSG0000014 = structure(list(name = c("E-1122O", "E-11EM3",
"E-11EMC", "E-1442O", "E-1132O"), ENSG = c("ENSG0000014", "ENSG0000014",
"ENSG0000014", "ENSG0000014", "ENSG0000014"), expr = c(" 9.940670e-02",
" 1.289670e-01", "-7.394904e-03", " 9.940670e-02", " 9.940670e-02"
), `1_43222779_A_G_b37` = c("1", "1", "2", "1", "0"), `1_43222856_A_G_b37` = c("0",
"0", "0", "1", "1"), `1_43223126_C_T_b37` = c("0", "1", "0",
"1", "2"), `1_43223317_T_C_b37` = c("1", "0", "0", "2", "1")), row.names = c(NA,
-5L), class = c("tbl_df", "tbl", "data.frame")), ENSG0000016 = structure(list(
name = c("E-1122O", "E-11EM3", "E-11EMC", "E-1442O", "E-1132O"
), ENSG = c("ENSG0000015", "ENSG0000015", "ENSG0000015",
"ENSG0000015", "ENSG0000015"), expr = c(" 9.940670e-02",
" 1.289670e-01", "-7.394904e-03", " 9.940670e-02", " 1.289670e-01"
), `1_43222779_A_G_b37` = c("0", "1", "0", "1", "2"), `1_43222856_A_G_b37` = c("1",
"1", "2", "1", "0")), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame")))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们从这两个列表中获得
Intersect
ing name 然后使用它来子集list
We get the
intersect
ing names from both lists and then use that to subset thelist