title: Calculating the median of data in a frequency table
body: <p>I want to calculate the median age for each group in this data frame:</p>
  <pre><code>dfx&lt;-data.frame(group=c(1:100),
                 `1`=rnorm(100,50,0.5),
                 `2`=rnorm(100,45,15),
                 `3`=rnorm(100,17,5))
  colnames(dfx) &lt;- c(&quot;group&quot;, &quot;1&quot;,&quot;2&quot;,&quot;3&quot;)
  </code></pre>
  <p>Which shows the number of individuals aged 1 - 3 for different groups (the real dataframe has over 100 columns and runs from age 0 - 90+).</p>
  <pre><code># A tibble: 100 × 4
     group   `1`   `2`   `3`
     &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
   1     1  49.7  39.5 15.2 
   2     2  49.0  41.4 20.3 
   3     3  49.5  74.8  8.31
   4     4  50.0  34.4 18.2 
   5     5  49.9  41.5 17.1 
   6     6  49.7  40.4 21.0 
   7     7  49.6  72.6 23.8 
   8     8  50.4  41.9 14.9 
   9     9  50.3  63.8 17.8 
  10    10  50.0  34.7 26.2 
  # … with 90 more rows
  </code></pre>
  <p>I want to calculate the median age for each group to produce something like this:</p>
  <pre><code>dfxx&lt;-data.frame(group=c(1:100),
                  med_age=rnorm(100,2,0.0001))
  </code></pre>
  <p>Note that these are meant to be integers, just like the original age data.</p>
  <pre><code># A tibble: 100 × 2
     group med_age
     &lt;int&gt;   &lt;dbl&gt;
   1     1    2.00
   2     2    2.00
   3     3    2.00
   4     4    2.00
   5     5    2.00
   6     6    2.00
   7     7    2.00
   8     8    2.00
   9     9    2.00
  10    10    2.00
  # … with 90 more rows
  </code></pre>
  <p>I assume I need to make a vector/histogram from the data before calculating the median, but I'm not sure how to do this.</p>
  <p>Thanks in advance!</p>