Reading Many CSV Files at the Same Time in R and Combining All into one dataframe -
i have 20 .csv files , of them have equal number of row/col (1 row , 42 columns). want make dataframe out of them , have each csv file 1 row of dataframe , have name of csv file row name. possible this?
to illustrate example:
a.csv 10 21 32 45 b.csv 33 45 93 90 c.csv 12 93 na 21
resulting dataframe looking be:
a 10 21 32 45 b 33 45 93 90 c 12 93 na 21
both data.table
(rbindlist
) , dplyr
(bind_rows
) have functions this. preferred solution use readr::read_csv
dplyr::bind_rows
this:
library(readr) library(dplyr) bind_rows( lapply( list.files( "path/to/csv_files", pattern = ".csv", full.names = true ), read_csv, header = false, na_strings = c("na") ) )
Comments
Post a Comment