title: Run correlation between unequal sized blocks of data in 2 time series
body: <p>I have two datasets and I need to estimate correlation of the series in these two datasets. For example, one series in of length 189 and the other series is of length 192. The end point of these series respond to the same time period ,i.e., Dec 2015. The difference is in the start point of this series. I need to estimate the correlation for the blocks of 12 data points in both the series starting from the last point. For ex, the first block would be from Jan 2015 to Dec 2015, second block would be from Jan 2014 to Dec 2014. Since the last block would have unequal data length, the data length can be equalized and the last block can be of less than 12 months. For example in the example, the last block would be of length 9 months. How to create a loop and run this? 
  I tried the following. This is giving me results but I am getting the same value of correlation for all the loop runs. DOn't know where am I going wrong.</p>
  
  <pre><code>correl=data.frame(x=numeric(0))
  r=nrow(US)
  s=nrow(Argentina)
  
  a=ifelse(r&lt;s,r,s)
  
  for (i in 1:(a%/%12)) {
    if(i&lt;a%/%12){
      elmnt1= US[r-11:r,]$IIP
      elmnt2= Argentina[s-11:s,]$IIP
    } else {
      elmnt1= US[1:r%%12,]$IIP
      elmnt2=Argentina[1:s%%12,]$IIP
    }
    corr=cor(elmnt1, elmnt2)
    correl$x[i,]=corr
    r=r-12
    s=s-12
  }
  </code></pre>