Using dplyr, how to reorder a dataframe based on a condition. Explain with an example in R.

441    Asked by Ronittyagi in Data Science , Asked on Nov 7, 2019
Answered by Ronit tyagi

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)))




Your Answer

Interviews

Parent Categories