title: Median across columns using a loop
body: <p>I have a dataframe regarding residents divided by age in certain towns. In other words I have something like this</p>
  
  <pre><code>Town        Aged18 Aged19 Aged20 Aged21 Aged22 Aged23 Aged24 Aged25 Total
  Rome        2      3      5      10     15     25     20     18     98
  Milan       15     19     21     25     25     20     35     15     175
  Turin       14     8      8      10     15     25     24     6      110
  Florence    10     15     15     10     25     10     5      5      95
  Bologna     15     10     25     10     15     10     25     20     130
  </code></pre>
  
  <p>I want to create a new column indicating in which "age" column does the median of the distribution of residents fall for each town. In other words I want to create something like this</p>
  
  <pre><code>Town    Aged18 Aged19 Aged20 Aged21 Aged22 Aged23 Aged24 Aged25 Total Median
  Rome     2      3      5      10     15     25     20     18     98   23
  Milan    15     19     21     25     25     20     35     15     175  22
  Turin    14     8      8      10     15     25     24     6      110  22,5
  Florence 10     15     15     10     25     10     5      5      95   21
  Bologna  15     10     25     10     15     10     25     20     130  22
  </code></pre>
  
  <p>Strictly speaking I want to create a loop which sums the content of each column until we reach the median position, which, if column's total is odd, corresponds to (n+1)/2, while, if it is even, it corresponds to (n/2+(n+1)/2)/2. This latter is the case of Turin in my dataframe, where I am averaging between 22 and 23 since they correspond to the columns where the 55th (110/2) and the 56th (111/2) observations are contained respectively. </p>
  
  <p>Therefore I want the new column not to compute the median accross the values of the columns (which is something we can do through rowMedian), but I want it to return the column(s) which contains the median observation. </p>
  
  <p>Can anyone help me with this?? Thank you so much, I hope this can be useful even for someone else trying to do something similar.</p>