Please help. I am trying to write a function that reads a directory full of files and reports the number of completely observed cases in each data file. The function should return a data frame where the first column is the name of the file and the second column is the number of complete cases.
This is my code and the output it produces:
complete <- function(directory, id = 1:332) {
files <- list.files(directory, full.names = TRUE)
nobs = numeric()
for (i in 1:length(id)) {
nobs <- sum(complete.cases(files[i]))
}
return(data.frame(id, nobs))
}
This is the output:
complete("specdata", 25:30)
id nobs
1 25 0
2 26 0
3 27 0
4 28 0
5 29 0
6 30 0
>
But the code is not counting the completed cases. Please help