Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在excel文件中迭代多个excel工作表_R_Tidyverse_Purrr - Fatal编程技术网

R 在excel文件中迭代多个excel工作表

R 在excel文件中迭代多个excel工作表,r,tidyverse,purrr,R,Tidyverse,Purrr,我有一个Excel文件,里面有大约30个选项卡。这些是列名 促销类型,产品新账户,占总额的百分比,总余额,占总额的百分比,平均余额,加权平均利率,保证金。我需要做两个手术。按原样加载表格,但指定每列的数据类型,然后将其重命名为Promo\u type,prod,New\u Acct,New\u Per,Total\u Bal,Per\u Bal,Avg\u Bal,Wtd\u Rate,Marg 我正在尝试使用tidyverse包中的purr库 我不确定这个代码有什么问题。非常感谢您的意见 `p

我有一个Excel文件,里面有大约30个选项卡。这些是列名
促销类型
产品新账户
占总额的百分比
总余额
占总额的百分比
平均余额
加权平均利率
保证金
。我需要做两个手术。按原样加载表格,但指定每列的数据类型,然后将其重命名为
Promo\u type
prod
New\u Acct
New\u Per
Total\u Bal
Per\u Bal
Avg\u Bal
Wtd\u Rate
Marg

我正在尝试使用
tidyverse
包中的
purr

我不确定这个代码有什么问题。非常感谢您的意见

`path <- "data_raw/Products/Product.xlsx"

combined_data <- 
  excel_sheets(path) %>% 
map_df(~{
read_excel(path, sheet = .x, trim_ws = TRUE,
           col_types = c("text", 
                         "text", 
                         "numeric", 
                         "guess", 
                         "numeric", 
                         "guess", 
                         "numeric", 
                         "numeric", 
                         "numeric")) %>%
colnames(combined_data) <- c("Promotion_Type",
                      "Product",
                      "New_Accounts",
                      "New_Acct_Percent",
                      "Total_Balances",
                      "Percent_Balance",
                      "Average_Balances",
                      "Weighted_Average_Rate",
                      "Margin")})
`path%

colnames(组合_数据)这就是你的想法吗

library(tidyverse)

path <- "data_raw/Products/Product.xlsx"

ctypes <- c("text", "text", "numeric", "guess", "numeric", "guess", "numeric", "numeric", "numeric")
cnames <- c("Promotion_Type", "Product", "New_Accounts", "New_Acct_Percent", "Total_Balances",
           "Percent_Balance", "Average_Balances", "Weighted_Average_Rate", "Margin")

combined_data <- path %>%
  excel_sheets() %>%
  map_df(~ read_excel(path, sheet = .x, trim_ws = TRUE, col_types = ctypes))

colnames(combined_data) <- cnames
库(tidyverse)

运行时,您会得到哪个错误路径?