Include .csv filename when reading data into r using list.files

前端 未结 2 1253
攒了一身酷
攒了一身酷 2021-01-14 11:28

I\'m aggregating a bunch of CSV files in R, which I have done successfully using the following code (found here):

  Tbl <- list.files(path = \"./Data/CSVs         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-14 12:19

    Here's my solution. Let me know if this helps.

    Tbl <- list.files(path = "./Data/CSVs/",
             pattern="*.csv", 
             full.names = T) %>% 
       map_df(function(x) read_csv(x, col_types = cols(.default = "c")) %>% mutate(filename=gsub(".csv","",basename(x)))) 
    

提交回复
热议问题