Let's assume that I've got a data.frame that is supposed to be sorted with respect to selected columns and I want to make sure that it is indeed a case. I could try something like:
library(dplyr)
mpg2 <- mpg %>%
arrange(manufacturer, model, year)
identical(mpg, mpg2)
[1] FALSE
but if the identical returns FALSE this only lets me know that a dataset is in incorrect order.
- What if I would like to inspect only those rows that are in fact in incorrect order? How can I filter those out of the whole dataset? (I need to avoid looping here at best, as the dataset I work with is pretty large)
- If the remaining variables (not used for ordering) are different for the same value of
manufacturer,model,year, howdplyr::arrangedecides which observation comes first? Does it preserve the order from original dataset (mpghere)?