title: Argument is of length 0, no NA's
body: <p>I have a dataframe that looks like this:</p>
  
  <pre><code>         logentrytime ord_lat_dt0 ord_lat_dt1 ord_lat_dt2 ord_lat_dt3 ord_lat_dt4 ord_lat_dt5 ord_lat_dt6 ord_lat_dt7 ord_lat_dt8 ord_lat_dt9 ord_num0 ord_num1 ord_num2
  1 2016-11-10 14:23:36           0           0           0           0           0           0  2016-02-12           0           0           0        0        0        0
  2 2016-11-10 14:22:22           0           0           0           0           0           0  2016-02-12           0           0           0        0        0        0
  3 2016-11-07 16:02:45           0           0           0           0           0           0  2016-02-12           0           0           0        0        0        0
  4 2016-11-07 21:10:00           0           0           0           0           0           0  2016-02-12           0           0           0        0        0        0
  5 2016-11-07 16:03:29           0           0           0           0           0           0  2016-02-12           0           0           0        0        0        0
  6 2016-11-10 14:23:05           0           0           0           0           0           0  2016-02-12           0           0           0        0        0        0
  </code></pre>
  
  <p>Where ord_lat_dt columns are last purchase date of a customer. ord_lat_dt[0-9] were pulled from different database tables. Thus each row represents one customer, and their last order date will be indicated in one of the 9 columns. </p>
  
  <p>I would like to merge these, but before I do, want to calculate "months_since_last_purchase" based on the date in each column. </p>
  
  <p>Thus, I have converted the date columns into character strings, and am looping through using these functions:</p>
  
  <pre><code>elapsed_time &lt;- function(end_date, start_date) {
    ed &lt;- as.POSIXlt(end_date)
    sd &lt;- as.POSIXlt(start_date)
    12 * (ed$year - sd$year) + (ed$mon - sd$mon)
  }
  
  
  convert_time &lt;- function(data, column){
    for(i in seq(1,length(data$column))){
      if((data$column[i]!= "0") ==TRUE){
        data$column[i] &lt;- elapsed_months(Sys.time(), as.Date(data$column[i], format="%Y/%m/%d"))
      }
    }
    return(data)
  }
  
  
  test1 &lt;- convert_time(test2, ord_lat_dt0)
  </code></pre>
  
  <p>But I obtain the error</p>
  
  <pre><code>Error in if ((data$column[i] != "0") == TRUE) { : 
    argument is of length zero
  </code></pre>
  
  <p>I've also tried changing the if statement to check :</p>
  
  <pre><code>grepl("[-]", data$column[i])==FALSE)
  </code></pre>
  
  <p>But I obtain the same error. </p>
  
  <p>Any ideas? </p>
  
  <p>If you decide to down vote, please explain to me what is wrong with my question. I am trying to learn and would like to make sure I am asking correctly. </p>
  
  <p>NOTE: I am having a different issue and have completely changed the question. Thus some of the comments below do not apply. Because of the down votes, I could not open a new question. </p>