Jim G.
Jim G.

Reputation: 15382

arrange vs. fct_reorder: Do they do the same thing?

Related: Difference of fct_reorder and reorder


Consider the code below from here and here.

My question:


library(tidyverse)

recent_grads <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-10-16/recent-grads.csv")
majors_processed <- recent_grads %>%
  arrange(desc(Median)) %>% # What is the benefit of doing this if we have an fct_reorder below and vice-versa? Don't they do the same thing?
  mutate(Major = str_to_title(Major),
         Major = fct_reorder(Major, Median))

majors_processed %>%
  View()

Upvotes: 0

Views: 620

Answers (1)

Jim G.
Jim G.

Reputation: 15382

As @Axeman noted:

arrange reorders rows. fct_reorder reorders factor levels. They are principally different things. Note that after the arrange one could just as well use fct_inorder instead of fct_reorder.

Upvotes: 2

Related Questions