Please help. I am trying to create 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 the code that I have created but it does not work. The answer under nobs should not be 0
complete <- function(directory, id = 1:332) {
files <- list.files(directory, full.names = TRUE)
nobs = numeric()
for (i in id) {
nobs <- sum(complete.cases(files))
}
return(data.frame(id, nobs))
}
The output the I get is :
> complete("specdata", 3)
id nobs
1 3 0
>