I have a list like:
mylist <- list(a = 1, b = list(A = 1, B = 2), c = list(C = 1, D = 3))
there is (without a loop) a way to identify the positions of elements, for example. if I want to replace the values ββof "C" with 5, and it does not matter where the element "C" is, can I do something like:
Aindex <- find_index("A", mylist) mylist[Aindex] <- 5
I tried grepl and the following will work in the current example:
mylist[grepl("C", mylist)][[1]][["C"]]
but this requires an assumption about the level of nesting.
The reason I ask is because I have a deep list of parameter values ββand a named vector of replacement values, and I want to do something like
replacements <- c(a = 1, C = 5) for(i in names(replacements)){ indx <- find_index(i, mylist) mylist[indx] <- replacements[i] }
Is this an adaptation to my previous question, update node (of unknown depth) using xpath in R? using R lists instead of XML
list r recursion nested
Abe
source share