我有一个包含多 Excel 表的文件,我想运行一个函数来读取每张表并从另一列中减去一列,然后计算平均值
我试过了
library(readxl)
average_working_hours <- function(Name) {
Name <- read_excel("~/Name.xlsx")
hours12 <- 12*60*60
av_wh_Name <- mean((Name$`Departure of staff`+ hours12) - Name$`Attendance of Staff`, na.rm = TRUE)
av_wh_Name
}
average_working_hours(Name = Noha)
have an ERROR
**Error in read_fun(path = path, sheet = sheet, limits = limits, shim = shim, :
Evaluation error: zip file 'C:/Users/user 2/Documents/Name.xlsx' cannot be opened.**
然后我尝试了
average_working_hours <- function(Name) {
Name <- read_excel(sprintf("~/%s.xlsx ",Name))
hours12 <- 12*60*60
av_wh_Name <- mean((Name$`Departure of staff`+ hours12) - Name$`Attendance of Staff`, na.rm = TRUE)
av_wh_Name
}
average_working_hours(Name = Noha)
have an ERROR
**Error in switch(ext, xls = "xls", xlsx = "xlsx", xlsm = "xlsx", if (nzchar(ext)) { :
EXPR must be a length 1 vector**
问题出在哪里?