Reputation: 585
If I have the following list
list1 <- list(list(a = 2, b = 3), list(c = 4, d = 5))
list2 <- list(e = "a", f = "b")
mylist <- list(list1, list2)
What is the easiest way to change the value of a
within mylist
to a different value (preferably in purrr
)?
Upvotes: 0
Views: 444
Reputation: 325
Or try purrr::modify_in
. This will return the mylist
object with the updated a
value.
purrr::modify_in(mylist, c(1, 1, "a"), "new_value")
Upvotes: 0
Reputation: 388862
Maybe you can use pluck
:
purrr::pluck(mylist, 1, 1, 'a') <- 'new_value'
Upvotes: 1