title: How can I calculate correlation dynamically in kdb
body: <p>I have a table of returns that I want to calculate correlation for every n rows, but I am not sure how to do that. To be more illustrative, my table t is</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>sym1</th>
  <th>sym2</th>
  <th>sym3</th>
  <th>sym4</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>3</td>
  <td>4</td>
  <td>5</td>
  <td>1</td>
  </tr>
  <tr>
  <td>0</td>
  <td>-1</td>
  <td>6</td>
  <td>4</td>
  </tr>
  <tr>
  <td>-3</td>
  <td>10</td>
  <td>8</td>
  <td>9</td>
  </tr>
  <tr>
  <td>-4</td>
  <td>19</td>
  <td>-1</td>
  <td>6</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>How can I calculate the correlation between sym1 and sym2/sym3/sym4 for row 1-3, then row 2-4 etc?</p>
  <p>Currently I can only specify column then calculate, but I am trying to find a way that I can fix sym1 and iterate through sym2-4. Here's my current code</p>
  <pre><code>(cor).'flip flip each {(til x)xprev\:y}[3;]each (sym1;sym2) from t
  </code></pre>