Using dplyr, how to reorder a dataframe based on a condition. Explain with an example in R.
Using dplyr, we can reorder a dataframe based on any value of a column using arrange() function which can reorder any values in ascending or descending order. For now as of example, let us explain with the mtcars dataset that is built in R.
head(mtcars)
Now we reorder the Data Frame by cyl first, then by descending wt. We can do the following
head(arrange(mtcars,cyl,desc(wt)))