0

The list:

l <- list(abc = tibble(a = c("a", "b", "c"), b = c("a", "b", "c"), c = c("a", "b", "c")),
          xyz = tibble(a = c("x", "y", "z"), b = c("x", "y", "z"), c = c("x", "y", "z")))

$abc
# A tibble: 3 x 3
  a     b     c    
  <chr> <chr> <chr>
1 a     a     a    
2 b     b     b    
3 c     c     c    

$xyz
# A tibble: 3 x 3
  a     b     c    
  <chr> <chr> <chr>
1 x     x     x    
2 y     y     y    
3 z     z     z  

The output should be:

abc <- tibble(a = c("a", "b", "c"), b = c("a", "b", "c"), c = c("a", "b", "c"))
# A tibble: 3 x 3
  a     b     c    
  <chr> <chr> <chr>
1 a     a     a    
2 b     b     b    
3 c     c     c  

xyz <- tibble(a = c("x", "y", "z"), b = c("x", "y", "z"), c = c("x", "y", "z"))
# A tibble: 3 x 3
  a     b     c    
  <chr> <chr> <chr>
1 x     x     x    
2 y     y     y    
3 z     z     z

The tibbles should be named after the elements of the list. I have to get two tibbles. The length of the list could vary, though, so it should be applied for an undefined length of list.

I can't find an online solution for this.

Dutschke
  • 277
  • 2
  • 15

1 Answers1

1
library(purrr)

l %>% iwalk(~assign(.y, .x, envir = globalenv()))
det
  • 5,013
  • 1
  • 8
  • 16