title: Correlation matrix to dataframe, by Date
body: <p>I have a data frame that contains factor columns and a date column. I am looking to figure out the most efficient way to calculate correlation for each factor pair for each date. Here is an example date frame that I'm working with.</p>
  
  <pre><code>structure(list(MktDate = structure(c(17865, 17865, 17865, 17896, 
  17896, 17896, 17927, 17927, 17927), class = "Date"), Var1 = c(1, 
  2, 3, 1, 2, 3, 1, 2, 3), Var2 = c(3, 5, 2, 4, 3, 2, 1, 2, 5), 
      Var3 = c(8, 7, 6, 9, 8, 9, 5, 8, 7)), class = "data.frame", row.names = c(NA, 
  -9L))
  </code></pre>
  
  <p>I'd like a date frame to be the result in a format similar to what is displayed below</p>
  
  <pre><code>MktDate,FactorPair,Correl
  2018-11-30,Var1Var2,-.32733
  2018-11-30,Var1Var3,-1
  2018-11-30,Var2Var3,.3273
  2018-12-31,Var1Var2,-1
  ...
  </code></pre>
  
  <p>I'm guessing that this can be easily accomplished using some form of dplyr and apply but I'm not certain how to do it without using a bunch of nested loops.</p>
  
  <p>I appreciate your help in advance.</p>