I need to write a line of R that can reference an element of a list using a dynamically generated name.
For example, if I have the list:
x <- list(a = "Foo", b = "Bar", c = "Salad")
And a variable
v1 <- sample(c("a", "b", "c"),1)
I need to be able to change an element of that list using something like
x$v1 <- "Something else"
This last line, of course, does not work. Any help greatly appreciated.