title: How to compute a time series of pairwise correlations
body: <p>I have a time series of multiple factors:</p>
  
  <pre><code>df = read.table(text="
      date        factor     stock    value
      30-Jun-17   DivYield    AAPL    0.05
      30-Jun-17   DivYield    GOOG    0.055
      30-Jun-17   DivYield    MSFT    0.02
      31-Jul-17   DivYield    AAPL    0.055
      31-Jul-17   DivYield    GOOG    0.05
      31-Jul-17   DivYield    MSFT    0.025
      30-Jun-17   PB          AAPL    12
      30-Jun-17   PB          GOOG    11
      30-Jun-17   PB          MSFT    16
      31-Jul-17   PB          AAPL    11
      31-Jul-17   PB          GOOG    12
      31-Jul-17   PB          MSFT    14
      30-Jun-17   ROE         AAPL    0.1
      30-Jun-17   ROE         GOOG    0.12
      30-Jun-17   ROE         MSFT    0.12
      31-Jul-17   ROE         AAPL    0.1
      31-Jul-17   ROE         GOOG    0.1
      31-Jul-17   ROE         MSFT    0.12
              ", header = TRUE)
  df$date = lubridate::dmy(df$date)
  </code></pre>
  
  <p>I need to compute the pairwise correlations between factors, and I need to do it every day.  The result for Pearson correlations would look something like:</p>
  
  <pre><code>Date        Factor1  Factor2 Correlation.Time.Series
  30-Jun-17   DivYield    PB      -0.998337488
  30-Jun-17   DivYield    ROE     -0.381246426
  30-Jun-17   PB          ROE     0.327326835
  31-Jul-17   DivYield    PB      -0.984324138
  31-Jul-17   DivYield    ROE     -0.987829161
  31-Jul-17   PB          ROE     0.944911183
  </code></pre>
  
  <p>Any ideas on how to attack this one?  </p>
  
  <p>Here's my first attempt:</p>
  
  <pre><code>library(tidyverse)
  df.spread = spread(df, key = factor, value = value)
  first.attempt = df.spread %&gt;%
      select(-stock) %&gt;%
      group_by(date) %&gt;%
      do(as.data.frame(cor(.[,-1])))
  </code></pre>
  
  <p>That seems to do it.  The problem is the output has no label showing me what the correlation is with:</p>
  
  <pre><code>        date   DivYield        PB         ROE
  1 2017-06-30  1.0000000 -0.9983375 -0.3812464
  2 2017-06-30 -0.9983375  1.0000000  0.3273268
  3 2017-06-30 -0.3812464  0.3273268  1.0000000
  4 2017-07-31  1.0000000 -0.9843241 -0.9878292
  5 2017-07-31 -0.9843241  1.0000000  0.9449112
  6 2017-07-31 -0.9878292  0.9449112  1.0000000
  </code></pre>