To read all files in a directory into a dataframe, with a column recording filename in R with the Tidyverse package, we can use the following code:
main.r649 chars27 lines
This code will read all .csv files in the specified directory into a dataframe, with a new column indicating the filename for each row of data. Note that we are using read_csv()
from the readr
package to read the files, and bind_rows()
from the dplyr
package to combine the dataframes. We are also using str_extract()
from the stringr
package to extract the filename from the file path. Don't forget to replace "path/to/directory" with the actual directory path you want to use.
gistlibby LogSnag