Last active
August 29, 2015 14:05
-
-
Save xingpel/5707e5134047feafe6de to your computer and use it in GitHub Desktop.
Check a list of csv files how many rows without any NA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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