Title: Why doesn't rev(factor) work as a way to reverse the wt argument of dplyr181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16top_n()?
Tags: r;dplyr;tidyverse;top-n
Question: Goal: return the row with thing1=F and thing2=MeFirst
Why does this not work?
```tibble(
    row = 1:10,
    thing1 = c(rep(&quot;F&quot;,5),rep(&quot;L&quot;,5)),
    thing2 = c(rep(&quot;MeSecond&quot;,4),rep(&quot;MeFirst&quot;,2),rep(&quot;MeSecond&quot;,4))
) %&gt;%
    mutate(
        thing1 = factor(thing1, levels = c(&quot;F&quot;, &quot;L&quot;)),
        thing2 = factor(thing2, levels = c(&quot;MeFirst&quot;, &quot;MeSecond&quot;))
    ) %&gt;%
    top_n(
        .,
        n = 1,
        wt = rev(thing1)
    ) %&gt;%
    top_n(
        .,
        n = 1,
        wt = rev(thing2)
    )
```
Above returns rows 2:5.
I know this does work:
```tibble(
    row = 1:10,
    thing1 = c(rep(&quot;F&quot;,5),rep(&quot;L&quot;,5)),
    thing2 = c(rep(&quot;MeSecond&quot;,4),rep(&quot;MeFirst&quot;,2),rep(&quot;MeSecond&quot;,4))
) %&gt;%
    mutate(
        thing1 = factor(thing1, levels = c(&quot;F&quot;, &quot;L&quot;)),
        thing2 = factor(thing2, levels = c(&quot;MeFirst&quot;, &quot;MeSecond&quot;))
    ) %&gt;%
    top_n(
        .,
        n = -1,
        wt = thing1
    ) %&gt;%
    top_n(
        .,
        n = -1,
        wt = thing2
    )
```
But the question is, why doesn't rev(thing2) work?



Here is another answer: The short answer is that you want to reverse the levels of the factor but not the factor itself:
```library(dplyr)
library(forcats)

tibble(row = 1:10,
       thing1 = c(rep(&quot;F&quot;, 5), rep(&quot;L&quot;, 5)),
       thing2 = c(rep(&quot;MeSecond&quot;, 4), rep(&quot;MeFirst&quot;, 2), rep(&quot;MeSecond&quot;, 4))) %&gt;%
  mutate(thing1 = factor(thing1, levels = c(&quot;F&quot;, &quot;L&quot;)),
         thing2 = factor(thing2, levels = c(&quot;MeFirst&quot;, &quot;MeSecond&quot;))) %&gt;%
  top_n(n = 1, wt = fct_rev(thing1)) %&gt;%
  top_n(n = 1, wt = fct_rev(thing2))

# A tibble: 1 x 3
    row thing1 thing2 
  <int&gt; <fct&gt;  <fct&gt;  
1     5 F      MeFirst
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:12/17/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<r><dplyr><tidyverse><top-n>', 'Title': "Why doesn't rev(factor) work as a way to reverse the wt argument of dplyr::top_n()?", 'ViewCount': 44, 'id': 65333079, 'user_AboutMe': None, 'user_AccountId': 9973426.0, 'user_DisplayName': 'Caleb Radens', 'user_Reputation': 1.0, 'user_Views': 9.0, 'user_id': 7378802.0}}