r - 编写一个 for 循环以在文件夹中的文件中执行相同的功能
问题描述
当我在文件上运行函数 nwc 时,它如图所示工作,但我想要一个 for 循环来调用文件夹中的所有文件来执行 nwc 函数。这没用。任何帮助将不胜感激。
nwc(nxmar_18)
#$Alloc_Matrix
# A tibble: 3 x 4
# D1 D2 D3 D4
# <dbl> <dbl> <dbl> <dbl>
#1 6 5 0 0
#2 0 5 8 0
#3 0 0 4 15
#$Total_Cost
# D1
#1 1095
不在 for 循环中工作。显示此错误
cost_aloc <- vector("double", length(mar_18))
for(p in mar_18){
nxmar_18 <- read_excel(p)
nxmar_18 <- nxmar_18[, -1]
cost_aloc[p] <- nwc(nxmar_18[[p]])
write.xlsx(cost_aloc, file = "out_put_8.xlsx")
print(cost_aloc)
}
新名称:* `` -> ...1 -nrow(ex_matrix) 中的错误:一元运算符的参数无效
解决方案
推荐阅读
- ansible - Ansible playbook 根据日期条件删除多个/单个文件
- protractor - 量角器 - 预期:+Nan 但实际:5
- c - 如何在vim中为C格式说明符和变量自定义颜色
- java - 在main方法中抛出异常后如何处理?
- excel - office-js:使用JS excel api作为前端数据表
- spring-boot-test - 如何使用 webmvctest 在 springboot 测试中启用异步?
- android - 解除绑定操作后Android Binder线程正在运行
- interface - 实现 UML 序列和类图
- python - 在 python 数据框中用增量值填充 NAN
- arrays - Laravel 从多维集合中展平和采摘