title: How to do ranking/factoring in R?
body: <p>In the following dataframe:</p>
  <pre><code>Year = c(&quot;2015&quot;, &quot;2015&quot;, &quot;2015&quot;, &quot;2015&quot;, &quot;2015&quot;,  &quot;2015&quot;, &quot;2015&quot;, &quot;2016&quot;, &quot;2016&quot;, &quot;2016&quot;, &quot;2016&quot;, &quot;2016&quot;, &quot;2016&quot;,  &quot;2016&quot;, &quot;2017&quot;, &quot;2017&quot;, &quot;2017&quot;, &quot;2017&quot;, &quot;2017&quot;, &quot;2017&quot;, &quot;2017&quot;,  &quot;2018&quot;, &quot;2018&quot;, &quot;2018&quot;, &quot;2018&quot;, &quot;2018&quot;, &quot;2018&quot;, &quot;2019&quot;, &quot;2019&quot;,  &quot;2019&quot;, &quot;2019&quot;, &quot;2019&quot;, &quot;2019&quot;)
  
  
  Region = c(&quot;World&quot;, &quot;Africa&quot;, &quot;Middle East&quot;, &quot;Europe&quot;, &quot;America&quot;, &quot;Asia&quot;, &quot;Other&quot;, 
  &quot;World&quot;, &quot;Africa&quot;, &quot;Middle East&quot;, &quot;Europe&quot;, &quot;America&quot;, &quot;Asia&quot;, &quot;Other&quot;, &quot;World&quot;, &quot;Africa&quot;, &quot;Middle East&quot;, &quot;Europe&quot;, &quot;America&quot;, &quot;Asia&quot;, &quot;Other&quot;, &quot;World&quot;, &quot;Africa&quot;, &quot;Middle East&quot;, &quot;Europe&quot;, &quot;America&quot;, &quot;Asia&quot;, &quot;World&quot;, &quot;Africa&quot;, &quot;Middle East&quot;, &quot;Europe&quot;, &quot;America&quot;, &quot;Asia&quot;)
  
  Sales = c(914141282, 1944898318,  4364067461, 11300678829, 16278485843, 132612907539, 6014323190,  1423729376, 2594259389, 3953198670, 12218027505, 17074884991,  140098809735, 6476302180, 1824592711, 4001928375, 4487385252,  13386187005, 19482623313, 173213703884, 8678149745, 2515250712,  3025785028, 5264852268, 15280791380, 20221401985, 187302084150,  1970503832, 2900497180, 5776217486, 16459966376, 22412702838,  200321533591)
  
  df &lt;- data.frame(Year, Region, Sales)
  
     Year      Region        Sales
  1  2015       World    914141282
  2  2015      Africa   1944898318
  3  2015 Middle East   4364067461
  ..............................
  30 2019 Middle East   5776217486
  31 2019      Europe  16459966376
  32 2019     America  22412702838
  33 2019        Asia 200321533591
  </code></pre>
  <p>I need to order regions according to &quot;Sales&quot; in the last year (2019 in this case), so I use the code below:</p>
  <pre><code>order &lt;- subset(df, Year == max(Year), select = c(&quot;Region&quot;,&quot;Sales&quot;)) %&gt;% arrange(-desc(Sales)) %&gt;% select(Region)
  df$Region &lt;- factor(df$Region, levels = order$Region)
  </code></pre>
  <p>However, problem is that Regions &quot;Other&quot; is not given in 2019, but it is in 2015, 2016 and 2017. that's why in the output there is NA:</p>
  <pre><code>   Year      Region        Sales
  1  2015       World    914141282
  2  2015      Africa   1944898318
  3  2015 Middle East   4364067461
  4  2015      Europe  11300678829
  5  2015     America  16278485843
  6  2015        Asia 132612907539
  7  2015        &lt;NA&gt;   6014323190 &lt;---------------
  8  2016       World   1423729376
  9  2016      Africa   2594259389
  10 2016 Middle East   3953198670
  11 2016      Europe  12218027505
  12 2016     America  17074884991
  13 2016        Asia 140098809735
  14 2016        &lt;NA&gt;   6476302180 &lt;---------------
  15 2017       World   1824592711
  16 2017      Africa   4001928375
  17 2017 Middle East   4487385252
  18 2017      Europe  13386187005
  19 2017     America  19482623313
  20 2017        Asia 173213703884
  21 2017        &lt;NA&gt;   8678149745 &lt;---------------
  22 2018       World   2515250712
  23 2018      Africa   3025785028
  24 2018 Middle East   5264852268
  25 2018      Europe  15280791380
  26 2018     America  20221401985
  27 2018        Asia 187302084150
  28 2019       World   1970503832
  29 2019      Africa   2900497180
  30 2019 Middle East   5776217486
  31 2019      Europe  16459966376
  32 2019     America  22412702838
  33 2019        Asia 200321533591
  </code></pre>
  <p>So I want the the following procedure:
  If one of the region is not given in 2019, they have to be ranked as last in the ranking order during factoring</p>