title: cor.test ,"not enough finite observations"
body: <p>I use two different ways to use <code>cor.test</code>, one in my own function, the other uses <code>cor.test</code> directly. When I use <code>cor.test</code> in my own function, it appeared an error, how could it happen?</p>
  
  <p>This was <strong>OK</strong></p>
  
  <pre><code>cor.test(x=cust_new$maintain_cust/cust_new$ttl_cust,
           y=cust_new$ttl_cust,alternative="two.sided",
           method="pearson",conf.level=0.95)
  </code></pre>
  
  <p>The following would give the error :</p>
  
  <blockquote>
    <p>"not enough finite observations"</p>
  </blockquote>
  
  <pre><code>cor_result&lt;-function(x,y,data){
    a&lt;-cor.test(x=as.numeric(data$x)/as.numeric(data$y),
                y=as.numeric(data$y),
                alternative="two.sided",method="spearman",
                conf.level=0.95)
    r&lt;-a$estimate
    p&lt;-a$p.value
    c&lt;-data.frame(r=r,p=p)
    return(c)
  }
  
  d&lt;-cor_result(x=maintain_cust,y=ttl_cust,data=cust_new)
  </code></pre>
  
  <p>The following would give the error :</p>
  
  <blockquote>
    <p>'y' must be a numeric vector"</p>
  </blockquote>
  
  <pre><code>cor_result&lt;-function(x,y,data){
    a&lt;-cor.test(x=data$x/data$y,y=data$y,
              alternative="two.sided",method="spearman",conf.level=0.95)
    r&lt;-a$estimate
    p&lt;-a$p.value
    c&lt;-data.frame(r=r,p=p)
    return(c)
  }
  
  d&lt;-cor_result(x=maintain_cust,y=ttl_cust,data=cust_new)
  </code></pre>
  
  <p><strong>dput(cust_new),a few sample</strong>:</p>
  
  <pre><code>structure(list(data_month = structure(c(16953, 16983, 17014, 
  17045, 17075, 17106, 16953, 16983, 17014, 17045), class = "Date"), 
      ttl_cust = c(383L, 580L, 735L, 850L, 952L, 1062L, 2418L, 
      2492L, 2515L, 2550L), maintain_cust = c(179L, 266L, 355L, 
      413L, 448L, 508L, 935L, 1026L, 1091L, 1143L)), row.names = c(NA, 
  10L), class = "data.frame", .Names = c("data_month", "ttl_cust", 
  "maintain_cust"))
  </code></pre>