getting list and list element name for a nested list in R

Viewed 2538

I made a nested list like the one below.

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)

now from this "nested list", i want to find out the which group an element belongs and which list element it belongs. Pardon my lack of understanding with list structure.

For example

test <- c("red", "tan")

given test i want the return of "color" "group1" and "taste" "group2"..

Is there any function to do this? I struggle with lists often. any help would be appreciated

2 Answers
Related