title: How to iterate PCA over rolling windows in R?
body: <p>I currently have a set of monthly time series data going back to 1993 for 16 variables.  I wrote the script to run PCA over the entire time period, but I need to run the calculations over rolling 12 month time periods in hindsight (so the first iteration would be for t=1 through t=12). I currently have:</p>
  
  <pre><code>path&lt;- "C:/Research/Datasets"
  setwd(path)
  variables&lt;- read.csv("Index (1993).csv")
  prin_comp&lt;- prcomp(variables)
  prin_comp$rotation[1:16, 1]
  std_dev&lt;-prin_comp$sdev
  pr_var&lt;- stddev^2
  prop_varex&lt;- pr_var/sum(pr_var)
  </code></pre>
  
  <p>I would also like to save the loadings on the first component for all iterations and the variation of the components, but I'm getting stuck on how to do these things.</p>
  
  <p>Any help would be greatly appreciated. Thanks in advance!</p>