How to `rearrange` values only if they are in a certain group?
It looks like you want to arrange the data first by ourid
, then by class
(descending), then by compid
, then by product
(descending). We're using descending for class
and product
because your desired order seems to be reverse alphabetical. If you have more than 2 categories of product or class, you could do a custom order by converting them to factor
class and specifying the order of the levels.
data %>% arrange(ourid, desc(class), compid, desc(product))