How can I turn the filename into a variable when reading multiple csvs into R

后端 未结 4 584
梦毁少年i
梦毁少年i 2021-01-03 08:58

I have a bunch of csv files that follow the naming scheme: est2009US.csv.

I am reading them into R as follows:

myFiles <- list.files(path=\"~/Dow         


        
4条回答
  •  时光取名叫无心
    2021-01-03 09:25

    You can create the object from lapply first.

    Lapply <- lapply(myFiles, read.csv, header=TRUE))
    names(Lapply) <- myFiles
    for(i in myFiles) 
        Lapply[[i]]$Source = i
    do.call(rbind, Lapply)
    

提交回复
热议问题