title: Correlation with different vector length
body: <p>I asked a question regarding this earlier which was migrated to stats.stackexchange</p>
  
  <p>After answers from there I had some questions regarding implementation in R to solve this and thought I should ask them here.  </p>
  
  <p>This is what I would like to produce: </p>
  
  <p>I have two seperate colums, price and time, for each equity. If the time is present for equity X but not equity Y then the previous price should be put into the vector and vice versa. </p>
  
  <p>Is a if loop the solution here? 
  Thanks for your help.</p>
  
  <p>As the following example: </p>
  
  <pre><code>X           Y   
  price   time   price   time
  10     540     20  540
  11     541     21  541
  12     542     22  543
  13     544     23  544
  14     545     24  545
  
  price   time   price   time
  10     540     20  540
  11     541     21  541
  12     542     21  542
  12     543     22  543
  13     544     23  544
  14     545     24  545
  </code></pre>