@arrange
Arranging is the way to sort a data frame. @arrange()
can take multiple arguments. Arguments refer to columns that are sorted in ascending order by default. If you want to sort in descending order, make sure to wrap the column name in desc()
as shown below.
DataFrames.jl
does not currently support the sort()
function on grouped data frames. In order to make this work in TidierData.jl
, if you apply @arrange()
to a GroupedDataFrame, @arrange()
will temporarily ungroup the data, perform the sort()
, and then re-group by the original grouping variables.
using TidierData
using RDatasets
movies = dataset("ggplot2", "movies");
Sort both variables in ascending order¤
@chain movies begin
@arrange(Year, Rating)
@select(1:5)
@slice(1:5)
end
5×5 DataFrame
Row | Title | Year | Length | Budget | Rating |
---|---|---|---|---|---|
String | Int32 | Int32 | Int32? | Float64 | |
1 | Blacksmith Scene | 1893 | 1 | missing | 7.0 |
2 | Hadj Cheriff | 1894 | 1 | missing | 4.1 |
3 | Glenroy Bros., No. 2 | 1894 | 1 | missing | 4.2 |
4 | Leonard-Cushing Fight | 1894 | 1 | missing | 4.4 |
5 | Sioux Ghost Dance | 1894 | 1 | missing | 4.4 |
Sort in a mix of ascending and descending order¤
To sort in descending order, make sure to wrap the variable inside of desc()
.
@chain movies begin
@arrange(Year, desc(Rating))
@select(1:5)
@slice(1:5)
end
5×5 DataFrame
Row | Title | Year | Length | Budget | Rating |
---|---|---|---|---|---|
String | Int32 | Int32 | Int32? | Float64 | |
1 | Blacksmith Scene | 1893 | 1 | missing | 7.0 |
2 | Luis Martinetti, Contortionist | 1894 | 1 | missing | 6.1 |
3 | Caicedo (with Pole) | 1894 | 1 | missing | 5.8 |
4 | Glenroy Brothers (Comic Boxing) | 1894 | 1 | missing | 5.4 |
5 | Buffalo Dance | 1894 | 1 | missing | 5.0 |
This page was generated using Literate.jl.