[英]The fastest way to import datasets with comomn characters in their names?
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.