rimportdataset

The fastest way to import datasets with comomn characters in their names?


I have the following sets of data into the directory I am working with, each with a similar name pattern

  AZ-K-HIP-TST.xls 
  AZ-K-HIP-MOD.xls 
  AZ-K-LUX-MOD.xls 
  AZ-Z-HIP-TST.xls 
  AZ-Z-HIP-MOD.xls 
  AZ-Z-LUX-MOD.xls 
  AZ-M-HIP-TST.xls 
  AZ-M-HIP-MOD.xls 
  AZ-M-LUX-MOD.xls 

As you could see they are named with common chacrters they share each other. Could anyone suggest any possible way to import them all together in one round?


Solution

  • list.files with pattern would give the name of the files in the directory, you may use lapply/map to import them together.

    #select files that start with RP and end with extension xls.
    filenames <- list.files(pattern = '^RP.*\\.xls$')
    data <- purrr::map(filenames, readxl::read_excel)
    

    If all the files have same column names and you would like to import them as one combined dataframe then use purrr::map_df instead of purrr::map.