Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

JavaScript
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)
}
Posted
Updated 12-Aug-15 10:35am
v3
Comments
Patrice T 12-Aug-15 16:26pm    
What is the language ?
Where did the error occurs ?
What your code is supposed to do ?
CPallini 12-Aug-15 16:30pm    
https://en.wikipedia.org/wiki/R_(programming_language)
Vinayak Bakshi 12-Aug-15 17:16pm    
Is this supposed to be the solution?
CPallini 12-Aug-15 17:26pm    
Nope, of course.
Vinayak Bakshi 12-Aug-15 17:13pm    
i wasn't able to find R tag. iv mentioned it in the headline dat its R programming course from coursera.
Where the error occurred is visible in the error report which iv mentioned.
code calculates no of complete cases in the dataset. iv mentioned the problem above as well. kindly go thorugh the script.

1 solution

I recommend to use the debugger.
run the program step by step, you will see where is the error.
You will be able to inspect variables.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900