Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.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中使用循环和rbind添加不同的.csv文件(在R中首次)_R_Csv - Fatal编程技术网

在R中使用循环和rbind添加不同的.csv文件(在R中首次)

在R中使用循环和rbind添加不同的.csv文件(在R中首次),r,csv,R,Csv,因此,我有一堆不同的.csv文件,我想将它们合并到一个数据帧中,以便在最后运行代码表。我想做的是检查文件名[V(x)],如果x

因此,我有一堆不同的.csv文件,我想将它们合并到一个数据帧中,以便在最后运行代码表。我想做的是检查文件名[V(x)],如果x<7,那么它会将[V(2:7)]合并在一起。我发现了类似的问题,但我真的不知道如何设置[V(x)]的条件。这是我到目前为止得到的,我没有得到正确数量的观察结果

#Import data from all versions of survey
setwd("~09 Export")

#Change the following when new versions are added
allVer <- c(2, 3, 4, 5, 6, 7)
curVer <- 7
oldVer <- c(2, 3, 4, 5, 6)

#loop
dta <- data.frame()
for (i in allVer){
    dta <- rbind(dta, read.csv(paste("NH School Choice Survey [V", i, "]", ".csv", sep = "")), header = TRUE, stringsAsFactors = FALSE, fill = TRUE)
if (i < curVer){
    dta <- rbind(dta, read.csv(paste("NH School Choice Survey [V", i, "]", ".csv", sep = "")), header = TRUE, stringsAsFactors = FALSE, fill = TRUE)
    }
}
for (i in oldVer){
    dta <- rbind(dta, read.csv(paste("NH School Choice Survey [V", i, "]", ".csv", sep = "")), header = TRUE, stringsAsFactors = FALSE, fill = TRUE)
}

dta$completed <- dta$anyStudent == 1
table(dta$idSurveyor, dta$completed)
#从所有版本的调查中导入数据
setwd(“~09导出”)
#添加新版本时,请更改以下内容
所有可能与
list.files(pattern=“\\[V[2-7]\\]”)的组合都是
。另请参见。类似于
dta_list=lappy(list.files());allver=data.table::rbindlist(dta\u列表)
应该是一个好的开始。所以我正在尝试
dta\u列表成功<代码>\\\[V[2-7]\\]根据最旧的最新版本进行更改。nhlist