我制作了一个与下面类似的嵌套列表。
group1 <- list(color = c("red", "green", "blue"),taste = c("sweet", "sour"))
group2 <- list(color = c("orange","purple","yellow"),taste = c("tan", "salt"))
nestedlist <- list(group1, group2)
现在从这个“嵌套列表”中,我想找出一个元素属于哪个组以及它属于哪个列表元素。请原谅我对列表结构的理解不足。
例如:
test <- c("red", "tan")
给定一个测试,我想要返回"color" "group1"和"taste" "group2"的结果。
是否有任何函数可以做到这一点?我经常在列表方面遇到困难。任何帮助都将不胜感激。
nestedlist <- list(g1 = group1, g2 = group2)
而不是nestedlist <- list(group1, group2)
吗?这样,你可以直接对unlist(nestedlist)
进行搜索。 - Aramis7dnestedlist <- list(g2.g1 = group1, g2 = group2)
的嵌套列表时,情况可能会变得困难。 - thelatemail