title: How to compute the daily avg correlation on intraday data using the xts package?
body: <p>I have intra-day history for a bunch of stocks. I am trying to compute the 1-minute correlation between stocks on a daily basis. My aim is to use the daily average per pair over a period to identify optimal pairs for a specific trading strategy.</p>
  
  <p>My idea is to loop through the trading days, compute intra-day 1-minute correlation, compute avg over all trading days, next pair.</p>
  
  <p>However, I am getting stuck at looping through the trading days.</p>
  
  <pre><code>my.xts.A &lt;- xts(A_Frame[,-1], order.by=A_Frame[,1])
  my.xts.B &lt;- xts(B_Frame[,-1], order.by=B_Frame[,1])
  
  my.min.A &lt;- to.minutes(my.xts.A[,1],1,'minutes')
  my.min.B &lt;- to.minutes(my.xts.B[,1],1,'minutes')
  
  my.day &lt;- to.daily(my.xts.A[,1],1)
  
  my.index &lt;- index(my.day)
  </code></pre>
  
  <p>I get the trading days in <code>my.index</code>, could someone please give me some guidance as to how to select a subset of <code>my.min.A</code> where <code>my.index[i] == day(my.min.A)</code>?</p>
  
  <p>thanks</p>
  
  <p>edit:</p>
  
  <pre><code>dput(head(my.min.A, 20))
  structure(c(3575, 3630, 3649, 3630, 3614, 3612, 3612, 3616, 3615, 
  3602, 3602, 3602, 3605, 3605, 3605, 3605, 3605, 3604, 3604, 3605, 
  3682, 3630, 3649, 3630, 3614, 3612, 3612, 3616, 3615, 3602, 3602, 
  3606, 3605, 3605, 3605, 3605, 3605, 3605, 3604, 3608, 3575, 3630, 
  3649, 3630, 3612, 3612, 3610, 3616, 3615, 3602, 3602, 3601, 3604, 
  3603, 3604, 3604, 3604, 3604, 3604, 3604, 3682, 3630, 3649, 3630, 
  3612, 3612, 3610, 3616, 3615, 3602, 3602, 3604, 3604, 3604, 3604, 
  3604, 3605, 3604, 3604, 3605), tclass = c("POSIXct", "POSIXt"
  ), tzone = "", class = c("xts", "zoo"), .indexCLASS = c("POSIXct", 
  "POSIXt"), .indexTZ = "", index = structure(c(1352790059, 1352790290, 
  1352790306, 1352790467, 1352790521, 1352790547, 1352790757, 1352791124, 
  1352791222, 1352791466, 1352791576, 1352791750, 1352791859, 1352791891, 
  1352791970, 1352792006, 1352792041, 1352792149, 1352792181, 1352792227
  ), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(20L, 
  4L), .Dimnames = list(NULL, c("minutes.Open", "minutes.High", 
  "minutes.Low", "minutes.Close")))
  </code></pre>