title: Returning a data frame
body: <p>I am using the following code to extract the number of complete cases from files:</p>
  
  <pre><code>complete &lt;- function(directory, id=1:332) {
      sapply(id, fn, directory)}
  
  
  fn &lt;- function(id, directory) {
      zero &lt;- sprintf("%03d", id)
      name &lt;- paste(directory,"/",zero,".csv",sep="")
      frame &lt;- read.csv(name)
      ok &lt;- complete.cases(frame)
      return(c("nobs"=sum(ok),"id"=id)) }
  </code></pre>
  
  <p>Then, e.g.: </p>
  
  <pre><code>complete("specdata",1:12)
  </code></pre>
  
  <p>This code returns:</p>
  
  <pre><code>     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
  nobs  117 1041  243  474  402  228  442  192  275   148   443    96
  id      1    2    3    4    5    6    7    8    9    10    11    12
  </code></pre>
  
  <p>However, I would like it to return a data frame of the type:</p>
  
  <p><img src="https://i.stack.imgur.com/mf2jh.png" alt="enter image description here"></p>
  
  <p>I am not sure what I am doing wrong. Thank you!</p>