title: I'm trying to construct a correlation matrix between groups in a panel data. Is there an easy way to do it on R? My dataset looks like as follow
body: <p>I have years between 1980 to 2000 where each year has repetitive id's. So I'm trying to calculate a correlation coefficient of one variable between id1 and id2 through the years. So I try the following code;</p>
  <pre><code>\ddply(df, .(id), summarise, &quot;corr&quot; = cor(x1, x2 = &quot;spearman&quot;))\
  </code></pre>
  <p>However what I would like to calculate is similar to following;</p>
  <pre><code>\ddply(df, .(id), summarise, &quot;corr&quot; = cor(x1|id1, x1|id2 = &quot;spearman&quot;))\
  </code></pre>
  <p>So, I can have between-id correlations of x1?</p>