I'm going through coursera R progrmming course. the assignment question im doing is as follows:
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.
The dataset for this question: https://d396qusza40orc.cloudfront.net/rprog%2Fdata%2Fspecdata.zip
the error im getting is...
Error in [<-.data.frame(*tmp*, i, value = list(Date = 1:2191, sulfate = c(NA, : new columns would leave holes after existing columns
The code to my function is here:
complete<-function(directory, id=1:332){
file_names<-list.files("specdata", full.names=TRUE)
dat<-data.frame()
comp_dat<-c()
inc<-0
for(i in id){
dat[i]<-read.csv(file_names[i])
comp_dat[i]<-nrow(complete.cases(dat[i]))
inc<-inc+1
}
show_result<-data.frame(inc,comp_dat)
head(show_result)
}