2

How can I create a list based on a character vector of names of objects that are themselves lists?

Minimal example

l1 <- list(letters, 1:10)
l2 <- list(LETTERS, 1:5)

list_names <- as.list(paste0("l", 1:2))

list(list_names)
[[1]]
[[1]][[1]]
[1] "l1"

[[1]][[2]]
[1] "l2"

The result is not what I want. I guess I somehow need to use backticks or soemthing such that l1 and l2 are not interpreted as character strings.

How would I do that?

Manuel R
  • 3,976
  • 4
  • 28
  • 41

1 Answers1

4

We can use mget to return the values of the object names

mget(paste0('l', 1:2))
akrun
  • 874,273
  • 37
  • 540
  • 662
  • 1
    If I could only remember everything I've read... I forgot about `mget`..thanks thats exactly what I was looking for. – Manuel R Jan 11 '17 at 09:32