读取Excel文件的文件夹,并将单个表作为单独的df&extim
我有一个excel文件的文件夹,每个文件都包含多个图纸。每个WB中的床单都相同。我正在尝试将所有Excel文件作为单独的数据帧导入一个特定的命名表。我已经能够进口它们;但是,名称成为df_1,df_2,df_3等...我一直在尝试将Excel文件名的第一个单词命名,并使用它来识别DF。
Excel文件名称“ AAPL多片”的示例该表将被命名为“ balance”,我将作为DF导入。结果,我希望“ AAPL Balance DF”。
但是,最接近我所在的代码,但是,它将每个数据框架称为df_1,df_2等。
library(purrr)
library(readxl)
files_list <- list.files(path = 'C:/Users/example/Drive/Desktop/Total_Related_Data/Analysis of Data/',
pattern = "*.xlsx",full.names = TRUE)
files_list %>%
walk2(1:length(files_list),
~ assign(paste0("df_", .y), read_excel(path = .x), envir = globalenv()))
我尝试在过去0函数中使用文件路径变量'file_list'标记它们并最终出现,
df_c:/ /desktop/total_releated_data/数据/.xlsx2的分析,
依此类推。
我试图列出要使用的文件名列表。这读取文件名并创建了一个列表,但我无法与上面的代码一起使用。
files_Names<-list.files(path='C:/Users/example/Drive/Desktop/Total_Related_Data/Analysis of Data/', pattern=NULL, all.files=FALSE, full.names=FALSE)
因此, 列表中所有文件的data.xlsx的AAPL分析。
I have a folder of excel files that contain multiple sheets each. The sheets are named the same in each wb. I'm trying to import one specific named sheet for all excel files as separate data frames. I have been able to import them in; however, the names become df_1, df_2, df_3, etc... I've been trying to take the first word of the excel file name and use that to identify the df.
Example of Excel file Name "AAPL Multiple Sheets" the sheet would be named "Balance" I'm importing as a df. I would like "AAPL Balance df" as the result.
The code that came closest to what I'm looking for located below, however, it names each data frame as df_1, df_2, and so on.
library(purrr)
library(readxl)
files_list <- list.files(path = 'C:/Users/example/Drive/Desktop/Total_Related_Data/Analysis of Data/',
pattern = "*.xlsx",full.names = TRUE)
files_list %>%
walk2(1:length(files_list),
~ assign(paste0("df_", .y), read_excel(path = .x), envir = globalenv()))
I tried using the file path variable 'file_list' in the past0 function to label them and ended up with,
df_C:/Users/example/Drive/Desktop/Total_Related_Data/Analysis of Data/.xlsx1, df_C:/Users/example/Drive/Desktop/Total_Related_Data/Analysis of Data/.xlsx2,
and so on.
I tried to make a list of file names to use. This read the file names and created a list but I couldn't make it work with the code above.
files_Names<-list.files(path='C:/Users/example/Drive/Desktop/Total_Related_Data/Analysis of Data/', pattern=NULL, all.files=FALSE, full.names=FALSE)
Which resulted with this,
"AAPL Analysis of Data.xlsx" for all the files in the list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行以下操作(请注意,我正在使用OpenXLSX软件包在Excel文件中读取,但是您当然可以用ReadXl替换该部分):
You can do the following (note that I'm using the openxlsx package for reading in Excel files, but you can replace that part with readxl of course):
我希望我可以在没有代码的情况下重现您的示例。我将创建一个功能,以获得新的文件名的更多控制权。
我建议:
让我知道它是否有效。我认为您只是针对“余额”表的目标?
I hope I could reproduce your example without code. I would create a function to have more control for the new filename.
I would suggest:
Let me know if it works. I assume you are just targeting for the sheet "Balance"?