title: Correlation between NA columns
body: <p>I have to write a function that takes a directory of data files and a threshold for complete cases and calculates the correlation between sulfate and nitrate (two columns) from each file where the number of completely observed cases (on all variables) is greater than the threshold. The function should return a vector of correlations for the monitors that meet the threshold requirement. If no files meet the threshold requirement, then the function should return a numeric vector of length 0. A prototype of this function follows</p>
  
  <p>My code looks like this</p>
  
  <pre><code>corr &lt;- function(directory,threshold=0){
      a&lt;-list.files("specdata")
      for (i in a) {
          data &lt;- read.csv(paste(directory, "/", i, sep =""))
          x&lt;-complete.cases(data)
          j&lt;-sum(as.numeric(x))
          sulfate&lt;-data[,2]
          nitrate&lt;-data[,3]
          b&lt;-cor(sulfate,nitrate)
      }  
      if (j&gt;threshold) 
          return(b) 
      else
          numeric()
  }
  </code></pre>
  
  <p>there's no error messege</p>
  
  <p>If I type</p>
  
  <blockquote>
    <p>z&lt;-corr("specdata")</p>
    
    <p>head(z)
        [1] NA</p>
  </blockquote>
  
  <p>I don't know what the problem is. I don't know if NA values in the columns have to do with it. I think something is missing in my code. I think the read.csv creates a unique data frame when I need one data frame per file but I don't see why the return is NA in this case (when there's no threshold).</p>
  
  <p>However, if I introduce a bigger threshold (1000):</p>
  
  <pre><code>z&lt;-corr("specdata",1000)
  head(z)
  numeric(0)
  </code></pre>
  
  <p>The expected output I need is</p>
  
  <pre><code>cr &lt;- corr("specdata", 150) 
  head(cr) 
  [1] -0.01895754 -0.14051254 -0.04389737 -0.06815956 -0.12350667 -0.07588814
  </code></pre>