If I have a variable such as name.string <- "name", how can I use that to assign the name of a value in a list to return something like
$name
[1] "value"
Using list(name.string = "value") returns $name.string [1] value.
And for reasons I can't seem to figure out, list(get("name.string") = "value") returns
Error: unexpected '=' in "list(get("name.string") =".
Obviously, I'm not interested in the manual solution (write "name" in the assignment) since this is being replicated for thousands of rows.
mylist <- list(name = "oldvalue"); mylist[[name.string]] <- "value"Is that what you're after?mylist <- list(); mylist[[name.string]] <- "value"; mylist[[name.string2]] <- "value2"should do that. You can try it out to see, or look athelp("[[")