Skip to content

Instantly share code, notes, and snippets.

@xingpel
Last active August 29, 2015 14:05
Show Gist options
  • Save xingpel/5707e5134047feafe6de to your computer and use it in GitHub Desktop.
Save xingpel/5707e5134047feafe6de to your computer and use it in GitHub Desktop.
Check a list of csv files how many rows without any NA
complete <- function(directory, id = 1:332) {
#1,create an output matrix
output <- NULL
#2,for each id file, calculate NA numbers
for (i in id){
num1 <- sprintf("%03d",i)
path <- paste(directory,num1,".csv",sep="")
data <- read.csv(path)
nobs <- 0
#read each line
for (j in 1:nrow(data)){
if (sum(is.na(data[j,])) == 0){
nobs <- nobs +1
}
}
output <- rbind(output,c(i,nobs) )
}
#3, create a new matrix output.
colnames(output)<- c("id","nobs")
output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment