Calculating median based on segments in r : <p>Hi I want to calculate the median of certain values based on the segment they fall into which we get by another column. The initial data structure is like given below:</p>

<pre><code>Column A    Column B  
559         1  
559         1  
322         1  
661         2  
661         2  
662         2  
661         2  
753         3  
752         3  
752         3  
752         3  
752         3  
328         4  
328         4  
328         4  
</code></pre>

<p>The calculated medians would be based on column A and the output would look like this:</p>

<pre><code>Column A    Column B    Median
559         1           559
559         1           559
322         1           559
661         2           661
661         2           661
662         2           661
661         2           661
753         3           752
752         3           752
752         3           752
752         3           752
752         3           752
328         4           328
328         4           328
328         4           328
</code></pre>

<p>Median is calculated based on column A and for the set of values of column B which are same. For example we should calculate medians of all values of column A where column B values are same and paste them in the column <strong>Median</strong>.</p>

<p>I need to do this operation in r but haven'e been able to crack it. Is there a way to do this through dplyr or any other package?</p>

<p>Thanks</p>
