0

I have a list with different elements inside:

df1 <- data.frame(a = c(1,2,3))
df2 <- data.frame(a = c(1,2,3), b = c("a","b","c"))
df3 <- data.frame(col = c("a","c","f","h","j"), col1 = c("a1","c2","f3","h4","j5"))
aList <- list(df1,df2,df3)

I would like to have one data frame for each element of the list. Basically I would like that aList to be back to df1, df2, and df3.

d.b
  • 29,772
  • 5
  • 24
  • 63
Bruno Guarita
  • 653
  • 7
  • 18
  • 4
    `list2env(setNames(aList, c("df1", "df2", "df3")), envir = .GlobalEnv)` – d.b Nov 15 '17 at 16:09
  • 1
    You could use `attach` or `assign`, but both are ill-advised. Usually a list of data frames is actually the best way to go. [Here's a nice post on the subject.](https://stackoverflow.com/a/24376207/4497050) – alistaire Nov 15 '17 at 16:12
  • It took me 3 hours to get to that!!!! Thanks d.b. One more question: that works for a list with 3 elements. df1, df2, df3. How can I do it for several data frames without the need to to c("df1", "df2", "df3")? – Bruno Guarita Nov 15 '17 at 16:15
  • 2
    @BrunoGuarita, replace `c("df1", "df2", "df3")` with `paste0("df", sequence(length(aList)))` – d.b Nov 15 '17 at 16:16
  • 1
    @d.b if this is not a duplicate, then perhaps convert your comment to an answer? – dww Nov 15 '17 at 16:20

0 Answers0