title: writing the outcome of a nested loop to a vector object in R
body: <p>I have the following data read into R as a data frame named "data_old":</p>
  
  <pre><code>   yes year month
  1  15 2004     5
  2   9 2005     6
  3  15 2006     3
  4  12 2004     5
  5  14 2005     1
  6  15 2006     7
  .   .  ...     .
  .   .  ...     .
  </code></pre>
  
  <p>I have written a small loop which goes through the data and sums up the yes variable for each month/year combination:</p>
  
  <pre><code>year_f &lt;- c(2004:2006)
  month_f &lt;- c(1:12)
  
  for (i in year_f){
      for (j in month_f){
          x &lt;- subset(data_old, month == j &amp; year == i, select="yes")
          if (nrow(x) &gt; 0){
              print(sum(x))
              }
          else{print("Nothing")}
          }
      }
  </code></pre>
  
  <p>My question is this: I can print the sum for each month/year combination in the terminal, but how do i store it in a vector? (the nested loop is giving me headaches trying to figure this out).</p>
  
  <p>Thomas</p>