So I have a bunch of different .csv files that I'd like to merge into a single data frame so I can run the code table at the end. What I'm trying to do is so it checks the name of the file [V(x)] so that if x < 7, then it merges [V(2:7)] together. I've found similar questions, but I can't really figure out how to put the condition for the [V(x)]. Here's what I have so far, and I'm not getting the right number of observations.
#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)