我做了一个如下所示的嵌套列表。获取R中的嵌套列表的列表和列表元素名称
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")
给定的测试,我想“颜色”,“组1”和“味道”,“组2”的回归..
是否有任何功能,这样做呢?我经常与列表斗争。任何帮助,将不胜感激
你试过'nestedlist < - 列表(G1 = 1组,G2 =第2组)',而不是'nestedlist < - 列表(1组,第2组) '?这样,你可以做'unlist(nestedlist)'并搜索它。 – Aramis7d
关于名称的公平点,但是当你有'nestedlist < - list(g2.g1 = group1,g2 = group2)'时,它会变得很困难。 – thelatemail