Hey everyone, beginner to R. I'm trying to reorder these bars in ascending order (or vice-versa) for the "starwars" dataset, but I'm not sure what I' doing wrong because I keep getting an error printed to my console when I run the code. I followed the exact syntax for the "msleep" dataset, and everything worked out fine in ascending and descending order. I can't get either order to work with the starwars dataset, however. Can someone explain what's wrong? Thank you.
Error in `mutate()`:
ℹ In argument: `name = fct_reorder(name, rev(height))`.
Caused by error in `lvls_reorder()`:
! `idx` must contain one integer for each level of `f`
Run `rlang::last_trace()` to see where the error occurred.
because your dataset contains multiple observations (rows) with the same height. Either filter first (and hope you've eliminated the duplicates), or order by height, make a new variable from row_number() and use that as the value to reorder the name factor.
It will work as long as some of your chosen Star Wars characters do not have the same height. You did not get an error because Luke Skywalker, Han Solo, and Greedo have different heights.