简体   繁体   English

导入名称中包含通用字符的数据集的最快方法?

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

I have the following sets of data into the directory:我在目录中有以下数据集:

在此处输入图片说明

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?任何人都可以提出任何可能的方法在一轮中将它们全部导入吗?

list.files with pattern would give the name of the files in the directory, you may use lapply / map to import them together. list.files with pattern将给出目录中文件的名称,您可以使用lapply / map将它们一起导入。

#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 .如果所有文件都具有相同的列名,并且您希望将它们作为一个组合数据purrr::map_df导入,则使用purrr::map_df而不是purrr::map

You can use list.files in collect your files and assign to create variable table names:您可以使用list.files收集文件并assign以创建变量表名称:

files <- list.files(pattern = "\\.xls")
for (i in 1:length(files)) {
  assign(gsub("\\.xls", "", files[i]), readxl::read_xls(files[i]))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM