Reputation: 165
I'm working on an algorithm that R contains 22 raster cells. These are being stored in memory. Each variable name that gun vector.
var_names <- c(list1,list2,list3,list4)
I use the following function, but it makes me only the first member in the vector variable.
eval(parse(text=var_names))
I need all the elements of the vector become variables.
Upvotes: 0
Views: 80
Reputation: 5893
Is this what you had in mind?
list1 <- list2 <- list3 <- list4 <- list(1,2)
var_names <- c("list1","list2","list3","list4")
sapply(var_names, function(x) eval(parse(text=x)))
list1 list2 list3 list4
[1,] 1 1 1 1
[2,] 2 2 2 2
Upvotes: 1