-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplete.R
28 lines (24 loc) · 993 Bytes
/
complete.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
complete <- function(directory, id = 1:332) {
#Initialize
nobs <- NULL;
#Iterate over id
for(i in id) {
#Name file
if(i < 10) {
filename <- paste(directory, "/00", as.character(i),".csv", sep = "")
} else if(i >= 10 && i < 100) {
filename <- paste(directory,"/0", as.character(i),".csv", sep = "")
} else if(i>=100) {
filename <- paste(directory,"/", as.character(i),".csv", sep = "")
}
#Make file connection
con <- file(filename,"r")
df <- read.csv(con, header=TRUE)
close(con)
#Get complete cases
good <- complete.cases(df)
complete <- df[good,]
nobs<-c(nobs, nrow(complete))
}
return(data.frame(id, nobs))
}