Convert list to list of lists
Apply the function list
to the list a
:
lapply(a, list)
[[1]]
[[1]][[1]]
[1] "A"
[[2]]
[[2]][[1]]
[1] "B"
[[3]]
[[3]][[1]]
[1] "C"
A possible solution, using purrr::map
:
library(purrr)
a = list('A', 'B', 'C')
b = list(list('A'), list('B'), list('C'))
a %>% map( ~ list(.x)) %>% identical(b)
#> [1] TRUE
a %>% map( ~ list(.x))
#> [[1]]
#> [[1]][[1]]
#> [1] "A"
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [1] "B"
#>
#>
#> [[3]]
#> [[3]][[1]]
#> [1] "C"
Or simply:
map(a, list)
Another base R option:
Map(list, a)
Output
[[1]]
[[1]][[1]]
[1] "A"
[[2]]
[[2]][[1]]
[1] "B"
[[3]]
[[3]][[1]]
[1] "C"
Benchmark
As suspected, lapply
is the fastest.