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:
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  
The calculated medians would be based on column A and the output would look like this:
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
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 Median.
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?
Thanks