0

I have the following dataframes that are stored in a list as a result of using the map() function:

enter image description here

How can I extract the six dataframes from the list? I would like to do this because I would like to give each column a different name of the dataframe and then store all data in a csv file? Or do I not have to extract the dfs from the list then?

Afke
  • 899
  • 2
  • 10
  • 21

2 Answers2

1

You have a few options

Fake data

library(tidyverse)

df <- tibble(a = 1:9,b = letters[1:9])


x <- list(df,df,df,df)

You can bind dfs and create just one

bind_rows(x)

You can execute your logic on all dfs

logic <- . %>% 
  mutate(c = a*3)

x %>% map(logic)

You can can also name the dfs inside the list

names(x) <- letters[1:4]

bind_rows(x,.id = "id")
Bruno
  • 4,109
  • 1
  • 9
  • 27
1

I am not sure about what you are exactly looking for, so below are something just from guessing your objective:

  • If you want to extract the data frame as objects in your global environment, then you can do like this:
list2env(setNames(dats1,paste0("df",seq(dats1))),envir = .GlobalEnv)
  • Assuming you are giving names "col1" and"col2" to two columns of different data frames in your list, maybe this can help you
dats1 <- lapply(dats1, setNames, c("col1","col2"))
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81