【问题标题】:how to convet this the code into a loop to be less repetitive如何将此代码转换为循环以减少重复
【发布时间】:2020-05-19 17:59:10
【问题描述】:
JUNE_2019_1 <- read_excel("G:/19011/2019 SALES/JUN 2019 P1.xlsx")
JUNE_2019_2 <- read_excel("G:/19011/2019 SALES/JUN 2019 P2.xlsx")
JUNE_2019_3 <- read_excel("G:/19011/2018 SALES/JUN 2019 P3.xlsx")

JULY_2019_1 <- read_excel("G:/19011/2019 SALES/JUL 2019 P1.xlsx")
JULY_2019_2 <- read_excel("G:/19011/2019 SALES/JUL 2019 P2.xlsx")
JULY_2019_3 <- read_excel("G:/19011/2019 SALES/JUL 2019 P3.xlsx")

AUG_2019_1 <- read_excel("G:/19011/2019 SALES/AUG 2019 P1.xlsx")
AUG_2019_2 <- read_excel("G:/19011/2019 SALES/AUG 2019 P2.xlsx")
AUG_2019_3 <- read_excel("G:/19011/2019 SALES/AUG 2019 P3.xlsx")

SEP_2019_1 <- read_excel("G:/19011/2019 SALES/sep 2019 P1.xlsx")
SEP_2019_2 <- read_excel("G:/19011/2019 SALES/sep 2019 P2.xlsx")
SEP_2019_3 <- read_excel("G:/19011/2019 SALES/SEP 2019 P3.xlsx")

OCT_2019_1 <- read_excel("G:/19011/2019 SALES/oct 2019 P1.xlsx")
OCT_2019_2 <- read_excel("G:/19011/2019 SALES/oct 2019 P2.xlsx")
OCT_2019_3 <- read_excel("G:/19011/2019 SALES/OCT 2019 P3.xlsx")
OCT_2019_4 <- read_excel("G:/19011/2019 SALES/OCT 2019 P4.xlsx")

NOV_2019_1 <- read_excel("G:/19011/2019 SALES/NOV 2019 P1.xlsx")
NOV_2019_2 <- read_excel("G:/19011/2019 SALES/NOV 2019 P2.xlsx")
NOV_2019_3 <- read_excel("G:/19011/2019 SALES/NOV 2019 P3.xlsx")

DEC_2019_1 <- read_excel("G:/19011/2019 SALES/DEC 2019 P1.xlsx")
DEC_2019_2 <- read_excel("G:/19011/2019 SALES/DEC 2019 P2.xlsx")
DEC_2019_3 <- read_excel("G:/19011/2019 SALES/DEC 2019 P3.xlsx")

此代码需要在循环中将此文件加载到我的工作区中,任何人都可以帮忙 这段代码需要循环加载这些文件到我的工作区,谁能帮忙

我的路径是(“G:/19011/2019 SALES/”),我仍然卡在这个

【问题讨论】:

    标签: r excel loops


    【解决方案1】:

    我们可以将文件夹中的所有文件放到list

    library(purrr)
    library(dplyr)
    library(readxl)
    files <- list.files("G:/19011/2019 SALES/", pattern = "\\.xlsx", full.names  = TRUE)
    lst1 <- map(files, read_excel)
    

    【讨论】:

    • 它给了我一个零列表
    • @SepaMostafa 你的意思是files 没有显示价值。请显示files的内容
    • 我不明白
    • @SepaMostafa 我的意思是files中的值是什么@
    • 文件中的字符(空)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    • 2018-12-29
    • 2014-11-27
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多