Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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中带双引号的循环_R - Fatal编程技术网

R中带双引号的循环

R中带双引号的循环,r,R,我正在尝试修改R中的一组excel文件。我目前正在尝试将数据集名称传递到read_excel中,如下所示 for(title in c("ABC.xlsx", "DEF.xlsx")){ library(readxl) data_a <- read_excel(paste("Directory/","\"", title,"\"", sep="")) data_a1 <- data_a[which(data_a$column_1!='NA'),] } 所以

我正在尝试修改R中的一组excel文件。我目前正在尝试将数据集名称传递到read_excel中,如下所示

for(title in c("ABC.xlsx", "DEF.xlsx")){

    library(readxl)
    data_a <- read_excel(paste("Directory/","\"", title,"\"", sep=""))
    data_a1 <- data_a[which(data_a$column_1!='NA'),]
}
所以我想我明白我没有正确地使用转义双引号,但是我尝试了很多不同的方法来解决这个问题,但我无法理解。我真的只想循环一些函数来修改我的数据,然后输出一些简单的统计数据。任何帮助都会很好。谢谢。

请删除粘贴中的“\”,然后文件路径将是“Directory/ABC.xlsx”,而不是“Directory/“ABC.xlsx”。

您只需要一次
库(readxl)
,通常位于代码的最顶端。 还请注意,
数据_a1
将在第二次读取时被覆盖。您将得到的只是“DEF.xlsx”数据

库(readxl)
用于(标题为c(“ABC.xlsx”、“DEF.xlsx”)){

数据\u a
读取\u excel(粘贴(“目录/”,标题,sep=”“)
应该没问题,因为引号不是字符串的一部分,所以不需要尝试转义。哇,太棒了,谢谢你。真不敢相信我尝试了这么多不同的组合,但都没有成功。现在只需要弄清楚如何在循环的控制台窗口中显示统计信息。我总是喜欢使用
标题
Error: 'Directory/"ABC.xlsx"' does not exist.
library(readxl)

for(title in c("ABC.xlsx", "DEF.xlsx")){
    data_a <- read_excel(paste("Directory/", title, sep=""))
    data_a1 <- data_a[which(data_a$column_1!='NA'),]
    }
Library(readxl)
data_a1 <- data.frame() # make an empty data frame
for(title in c("ABC.xlsx", "DEF.xlsx")) {
data_a <- read_excel(paste("Directory/", title, sep=""))
data_a1 <- rbind(data_a1, data_a) # assuming they have the same number of columns
}
data_a1 <- data_a1[which(data_a1$column_1 != NA),] # or "NA" if that is really present