Sort a dataframe column by the frequency of occurrence
<p>I have a dataframe in called df, there are three column lets say, </p>

<pre><code>Region ID  Salary
1      A1  100
1      A2  1001
1      A3  2000
1      A4  2431
1      A5  1001
..............
..............
2      A6  1002
2      A7  1002
2      A8  1002
3      A9  3001
3      A10 3001
3      A11 4001
</code></pre>

<p>Now I want to sort column Salary by the occurrence of them by Region, that is using frequency table or something, get the probability of occurrence per region and sort them. Please assume that the dataset is large enough (1000 rows)</p>

<p>P.S: Can anyone suggest a good method to do some. Please use column name in your answers since the real table has some column in the middle</p>

<p>Thanks in advance</p>

<pre><code>                  **EDIT 1**
</code></pre>

<p>I think I was not clear enough, thanks for all those who replied, I sincerely apologise for not being clear:</p>

<p>With the current dataset we need to create a frequency table say:</p>

<pre><code>Region  Salary(bin)     Count
1       1K              6                   
1       5K              3                   
1       2K              2                   
1       15K             2                   
1       0.5K            2                   
1       24K             1                   
1       0K              0                   
</code></pre>

<p>using this we can classify add a new columns in our data frame df called bin(bucket from histogram)</p>

<pre><code>Region     ID  Salary  (bin)   Count
    1      A1  100     1K      6
    1      A2  1001    2K      2
    1      A3  2000    2K      2
    1      A4  2431    5K      3
</code></pre>

<p>..........................So on...............</p>

<p>We can do the above using:</p>

<pre><code>df$bin &lt;- cut(df$salary, breaks=hist(df$salary)$breaks)
</code></pre>

<p>After sorting by Region and Count and Salary we get:</p>

<pre><code>Region     ID  Salary  (bin)   Count
    1      A1  100     1K      6
    1      A4  2431    5K      3
    1      A3  2000    2K      2
    1      A2  1001    2K      2
</code></pre>

<p>As you can see, we need to create frequency table for each region and do sort. I did the above using Tableau but I want to automate this in R</p>

<p>Hope I was clear</p>