title: Correlation in Panel Data with different number of observation for individuals
body: <p>I have the following panel data with some individuals having more observations than the others. </p>
  
  <pre><code>id &lt;- c("John","John","John","John","John",
          "Mike","Mike","Mike","Mike", 
          "Andrea","Andrea","Andrea","Andrea","Andrea","Andrea","Andrea")
  time &lt;- c(1:5, 1:4, 1:7)
  observation &lt;- c(rnorm(1:5), rnorm(1:4), rnorm(1:7))
  
  paneldata &lt;- data.frame(id, time, observation)
  </code></pre>
  
  <p>I want to calculate the correlation for the observations among the individuals. R should ignore the missing observations, e.g. </p>
  
  <p>Correlation between Mike and John: only time 1 to 4 should be considered</p>
  
  <p>Correlation between John and Andrea: only time 1 to 5  etc.</p>
  
  <p>What's the best way to achieve these results?</p>