How to write the dataframes in a list to a single csv file

前端 未结 2 1111
有刺的猬
有刺的猬 2021-01-16 11:48

I have a list with 15 data frames and they look like this

> head(final_data[[1]])
      DateTime # Unemployed Persons.csv
147 2013-03-01                          


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-16 12:30

    you can use the join-functions from the dplyr-package an put them in a loop like this:

    library(dplyr)
    #example list
    list <- list(
      data.frame("Date" = seq(as.Date("2016-01-01"), as.Date("2016-02-01"), "days"), 
                 "a" = 1:32), 
      data.frame("Date" = seq(as.Date("2016-01-01"), as.Date("2016-02-01"), "days"), 
                 "b" = 33:64), 
      data.frame("Date" = seq(as.Date("2016-01-01"), as.Date("2016-02-01"), "days"), 
                 "c" = 65:96))
    
    for (i in 1:length(list))
      if(i == 1) df <- list[[1]] else
        df <- left_join(df, list[[i]])
    

提交回复
热议问题