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

后端 未结 4 585
梦毁少年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:20

    Nrows <- lapply( lapply(myFiles, read.csv, header=TRUE), NROW)
    # might have been easier to store: lapply(myFiles, read.csv, header=TRUE)
    myDB$grp <- rep( myFiles, Nrows) )
    

提交回复
热议问题