title: R code creation of a Reusable function to calculate date difference of yearly data
body: <p>I have following 2 datasets
  VechicleParking_InTime</p>
  
  <pre><code>Vehicle_Id  12/31/15        12/30/15        12/29/15        12/27/15 
      2268    12/31/15 10:26  12/30/2015  14:00:00    12/29/15 11:00  NA
      2269    12/31/15 11:00  12/30/15 10:00  12/29/15 10:00  NA
      2270    12/31/15 0:00   12/30/15 7:00   12/29/15 7:00   NA
      2271    12/31/15 11:00  12/30/15 1:00   12/29/15 8:00   NA
      2272    12/31/15 10:00  12/30/15 4:00   12/29/15 9:00   12/27/15 1:00
      2273    NA  12/30/15 7:00   12/29/15 6:00   12/27/15 9:00
      2274    12/31/2015  15:00:00    12/30/15 10:00  12/29/15 5:00   12/27/15 7:00
  </code></pre>
  
  <p>VehicleParking_OutTime</p>
  
  <pre><code> Vehicle_Id 12/31/15    12/30/15    12/29/15    12/27/15 
  2268    12/31/15 11:26  NA  12/29/2015  13:00:00    NA
  2269    12/31/2015  13:00:00    12/30/2015  15:00:00    12/29/15 0:00   NA
  2270    12/31/15 9:00   12/30/2015  17:00:00    12/29/2015  17:00:00    NA
  2271    12/31/2015  23:00:00    12/30/2015  13:00:00    12/29/2015 18:00:00     NA
  2272    12/31/15 10:30  12/30/2015  14:00:00    12/29/2015  19:00:00    12/27/2015  13:00:00 
  
  2273    NA  12/30/2015  17:00:00    12/29/2015  16:00:00    12/27/2015 19:00:00 
  2274    12/31/2015  17:00:00    NA  12/29/2015 15:00:00     12/27/2015  17:00:00 
  </code></pre>
  
  <p>Following are my challenges
  1- The count of columns are 365 and every column name is date so I need a function which take columns as index to calculate the Time difference 
  2- Both intime and outtime are in different files</p>
  
  <p>I have created a function which is successfully working for calculating the date difference but when both are in same file with different column names</p>
  
  <pre><code>#Using Chron library
      Diff_Minutes &lt;- function(In_Time,Out_Time){
        if(is.na(In_Time) == TRUE){
          return(NA)
        }else{
          return((as.numeric(chron(dates=str_split_fixed(Out_Time," ",2)[,1],times=str_split_fixed(Out_Time," ",2)[,2],format=c('d-m-y','h:m:s'))) - as.numeric(chron(dates=str_split_fixed(In_Time," ",2)[,1],times=str_split_fixed(In_Time," ",2)[,2],format=c('d-m-y','h:m:s'))))*1440)
        }
      }
  </code></pre>