Problem with fct_reorder

I’m having an issue using fct_reorder. I’m using the airline-delay-2016-09 dataset in the Getting Started project and when I try to set a factor on ORIGIN and reorder the factor based on the average delay (column DELAY) I don’t see any difference.

Here is the command:
mutate(ORIGIN = factor(ORIGIN), ORIGIN = fct_reorder(ORIGIN, DEP_DELAY, fun=mean))

Is there something I’m doing wrong? This is on Version 3.3.0.2 (3.3.0.2).

Thanks,

Sanjay

Are you trying to see the difference in Summary view or Chart view? I’m seeing the difference with chart like Bar chart.

This is with the original ‘ORIGIN’ column.

This is with after ‘fct_reorder’.

Now one thing to note. DEP_DELAY column includes NAs, so you want to pass ‘na.rm=TRUE’ argument like below to get something we typically expect. R is very strict with NA, which is a good thing. :slight_smile:

fct_reorder(ORIGIN, DEP_DELAY, fun=mean,na.rm=TRUE)

Looks Summary view has some issue that it’s not reflecting the real factor levels. We’re looking into it.

Yes, the issue was with the Summary view. Thanks for looking into it (and also the tip about na.rm = TRUE).

Ok, this turned out to be a bug when there are more than 300 unique values (levels). We have just fixed it, and it will be included in the next patch release next week. Stay tuned!

This fix is in the latest release, v3.4.1. Please try it out. Let me know if you still see the issue.

It works correctly now. Thanks!

1 Like