title: d3.js: Converting Months to Quarter
body: <p>I'm trying to convert a csv with data in months format to quarter format (avg for quarter, not sum..)</p>
  
  <p>The output I need is a nested array, as shown below for the months, only for quarters. I've already calculated each quarter for month using the d3.nest function, but I can't seem to get it converted to quarters.</p>
  
  <p>Here is the csv with the data:</p>
  
  <pre><code>x,January,February,March,April,May,June,July
  Overall,3635,3371,3474,4212,4815,5544,4464
  A,1689,1489,1588,2231,2419,2889,2304
  B,316,266,267,323,337,354,435
  C,622,537,629,614,766,720,616
  </code></pre>
  
  <p>Here is the code that nests the data:</p>
  
  <pre><code>nest = d3.nest().key(function(d) { return d.x; })
                          .rollup(function(leaves) { var a = []; d3.entries(leaves[0]).forEach(function (k) { if (k.key != "x") a.push({x: k.key, y: k.value, month: k.key, quater: (Math.floor((new Date(Date.parse(k.key + "1, 2013")).getMonth()+1)/3+1))}); }); return a; });
  data = nest.entries(data);
  </code></pre>
  
  <p>Which results in (stipped to fit..):</p>
  
  <pre><code>[
     {
        "key":"Overall",
        "values":[
           {
              "x":"January",
              "y":"3635",
              "month":"January",
              "quater":1
           },
           {
              "x":"February",
              "y":"3371",
              "month":"February",
              "quater":1
           },
           {
              "x":"March",
              "y":"3474",
              "month":"March",
              "quater":2
           },
           {
              "x":"April",
              "y":"4212",
              "month":"April",
              "quater":2
           },
           {
              "x":"May",
              "y":"4815",
              "month":"May",
              "quater":2
           },
           {
              "x":"June",
              "y":"5544",
              "month":"June",
              "quater":3
           },
           {
              "x":"July",
              "y":"4464",
              "month":"July",
              "quater":3
           }
        ]
     },
     {
        "key":"A",
        "values":[
           {
              "x":"January",
              "y":"1689",
              "month":"January",
              "quater":1
           },
           {
              "x":"February",
              "y":"1489",
              "month":"February",
              "quater":1
           },
           {
              "x":"March",
              "y":"1588",
              "month":"March",
              "quater":2
           },
           {
              "x":"April",
              "y":"2231",
              "month":"April",
              "quater":2
           },
           {
              "x":"May",
              "y":"2419",
              "month":"May",
              "quater":2
           },
           {
              "x":"June",
              "y":"2889",
              "month":"June",
              "quater":3
           },
           {
              "x":"July",
              "y":"2304",
              "month":"July",
              "quater":3
           }
        ]
     },
     {
        "key":"B",
        "values":[
           {
              "x":"January",
              "y":"316",
              "month":"January",
              "quater":1
           },
           {
              "x":"February",
              "y":"266",
              "month":"February",
              "quater":1
           },
           {
              "x":"March",
              "y":"267",
              "month":"March",
              "quater":2
           },
           {
              "x":"April",
              "y":"323",
              "month":"April",
              "quater":2
           },
           {
              "x":"May",
              "y":"337",
              "month":"May",
              "quater":2
           },
           {
              "x":"June",
              "y":"354",
              "month":"June",
              "quater":3
           },
           {
              "x":"July",
              "y":"435",
              "month":"July",
              "quater":3
           }
        ]
     },
     {
        "key":"C",
        "values":[
           {
              "x":"January",
              "y":"622",
              "month":"January",
              "quater":1
           },
           {
              "x":"February",
              "y":"537",
              "month":"February",
              "quater":1
           },
           {
              "x":"March",
              "y":"629",
              "month":"March",
              "quater":2
           },
           {
              "x":"April",
              "y":"614",
              "month":"April",
              "quater":2
           },
           {
              "x":"May",
              "y":"766",
              "month":"May",
              "quater":2
           },
           {
              "x":"June",
              "y":"720",
              "month":"June",
              "quater":3
           },
           {
              "x":"July",
              "y":"616",
              "month":"July",
              "quater":3
           }
        ]
     }
  ]
  </code></pre>
  
  <p>Thanks in advance for the helpers!</p>