title: my dataframe giving wrong dimensions in r
body: <pre><code>  complete &lt;-function(directory,id){
  
    #path&lt;-directory
       mymatrix &lt;- matrix()
        rowc&lt;-1
   # mylist &lt;- list()
  
        for(i in id){
      fileStr &lt;- paste(directory, "/", sprintf("%03d", as.numeric(i)), ".csv", 
                       sep = "")
  
      #filename&lt;-paste(i,".csv",sep="")
      #mydata&lt;- read.csv((file=file.path(path, filename)), header=TRUE)
          mydata&lt;-read.csv(fileStr)
     #cleandframe&lt;- mydata[complete.cases(mydata),]
      numCOmpleteCases&lt;- sum(complete.cases(mydata))
  
     #mymatrix(i,numCOmpleteCases)
  
     # mylist[[rowc]]&lt;- cbind(c(i,numCOmpleteCases))
  
    mymatrix[rowc,] &lt;-c(i,numCOmpleteCases)
      rowc&lt;- rowc+1
      dframeComplete&lt;-data.frame(id=i,nobs=numCOmpleteCases)
  
  
    }
    #dframeComplete&lt;- (data.frame(id=id, nobs=sapply(id,numCompleteCases)))
    #dframeComplete
     mymatrix&lt;-as.data.frame(mymatrix)
     mymatrix
  
    }
  </code></pre>
  
  <p>I am trying to pruduce a dataframe with two columns, id and numCompleteCases, I have tried with both a list and a matrix, with a list I am getting a dataframe with columns equivalent to the number of pairs of (id,numCompleteCases) instead of a dataframe with 2 columns and a number of rows eqivalent to the pairs passed.</p>