title: how to use for loops to iterate bunch of codes for 15 years?
body: <p>I am really new in Stack community and also with R. I am trying to get three specific values after bunch of codes for one year i.e 2000.So, I get one row with three columns. However, I need to get those specific values as output for 14 more years, until 2014.How can I loop in a non-messy way, need some suggestion. I am trying following codes:</p>
  <pre><code>CVA &lt;-data.frame()
  for(i in 2000:2014) {
    
    
  D.2000 &lt;-  filter(Deu.niot.new, ...1==i)
  D.dom.2000 &lt;-filter(Deu.2000,...4==&quot;Domestic&quot;)
  
  D.imp.2000 &lt;-filter(Deu.2000,...4==&quot;Imports&quot;)
  
  
  D.ndom.2000 &lt;-select(Deu.2000.dom,-(...61:...67))
  D.nimp.2000 &lt;-select(Deu.2000.imp,-(...61:...67)) 
  </code></pre>
  <p>and so on....(MORE CODES)</p>
  <p>then, I need the below one as my final result:</p>
  <pre><code>CVA [[i,]]&lt;-cbind(cva.agri.2000,cva.manu.2000,cva.ser.2000)
  </code></pre>
  <p>Which means I need to create 14 more rows with 3 columns using for loops. Using above bunch of codes I just got the values for 2000. I need output as data.frame.</p>
  <p>Any hint or suggestion would be helpful!</p>
  <p>I used <strong>dput</strong> to show my data structure, seems really messy though:</p>
  <p>structure(list(...1 = c(2000, 2000, 2000, 2000, 2000, 2000, 2000,
  2000, 2000, 2000), ...2 = c(&quot;A01&quot;, &quot;A02&quot;, &quot;A03&quot;, &quot;B&quot;, &quot;C10-C12&quot;,
  &quot;C13-C15&quot;, &quot;C16&quot;, &quot;C17&quot;, &quot;C18&quot;, &quot;C19&quot;), ...3 = c(&quot;Crop and animal production, hunting and related service activities&quot;,
  &quot;Forestry and logging&quot;, &quot;Fishing and aquaculture&quot;, &quot;Mining and quarrying&quot;,
  &quot;Manufacture of food products, beverages and tobacco products&quot;,
  &quot;Manufacture of textiles, wearing apparel and leather products&quot;,
  &quot;Manufacture of wood and of products of wood and cork, except furniture; manufacture of articles of straw and plaiting materials&quot;,
  &quot;Manufacture of paper and paper products&quot;, &quot;Printing and reproduction of recorded media&quot;,
  &quot;Manufacture of coke and refined petroleum products&quot;), ...4 = c(&quot;Domestic&quot;,
  &quot;Domestic&quot;, &quot;Domestic&quot;, &quot;Domestic&quot;, &quot;Domestic&quot;, &quot;Domestic&quot;, &quot;Domestic&quot;,
  &quot;Domestic&quot;, &quot;Domestic&quot;, &quot;Domestic&quot;), ...5 = c(1180.79357309081,
  38.9191594938878, 0.0105591974138373, 20.3813413720862, 2717.28244274957,
  26.4883571262503, 47.5892951388691, 22.4047547307701, 31.3319695906172,
  444.595589525748), ...6 = c(82.985934075375, 417.382557034188,
  0, 0.353736300347672, 1.95091900568706, 1.19359373503498, 68.3727666976661,
  2.95275151914329, 4.46816919858237, 12.3444402345904), ...7 = c(0.0148890463411341,
  0.0168962782166389, 4.49517538484516, 0.030235623520195, 0.378606553315736,
  9.08182032551762, 1.07007663240345, 1.26467070570843, 0.905244246509581,
  2.4453813655119), ...8 = c(12.4358144539012, 23.2895865413182,
  0.0166626654844983, 76.2371092458133, 21.1129192358641, 2.88107063157295,
  47.303659680883, 68.154120909302, 33.2904033042654, 56.5944153631193
  ), ...9 = c(17952.563202823, 5.2593139999212, 22.4131588651991,
  116.814290718508, 14706.3043351145, 63.77989250888, 149.697280644864,
  1269.36851882589, 239.087006514138, 345.705681202278), ...10 = c(52.8680776105079,
  0.980236672662672, 0.00396924705354, 18.0442003449513, 81.890380752962,
  1623.56216722411, 28.8605439638297, 193.373586146434, 206.014971131385,
  61.8673029946462)), row.names = c(NA, -10L), class = c(&quot;tbl_df&quot;,
  &quot;tbl&quot;, &quot;data.frame&quot;))</p>
  <p>Only 10 rows are visible here so data for 2000 only. However the data frame consists of 15 years (2000 to 2014).</p>
  <h2><strong>Output should look like:</strong>
  |year |Agri |Manu | Ser|
  |:---:|:---:|:---:|:--:|
  |2000|value|value|value|</h2>
  <h2>|2001|value|value|value|</h2>
  <p>So, I need to store output of three values each year as final output. So, 15 rows with three columns.</p>