Skip to content

Commit

Permalink
orderby sortperm docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeffebach committed Mar 7, 2021
1 parent 66c64e0 commit bd4b531
Showing 1 changed file with 47 additions and 30 deletions.
77 changes: 47 additions & 30 deletions src/DataFramesMeta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,40 +496,57 @@ the given `DataFrame` on the result, returning a new `DataFrame`.
```jldoctest
julia> using DataFramesMeta, Statistics
julia> d = DataFrame(x = [3, 3, 3, 2, 1, 1, 1, 2, 1, 1], n = 1:10);
julia> d = DataFrame(x = [3, 3, 3, 2, 1, 1, 1, 2, 1, 1], n = 1:10,
c = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]);
julia> @orderby(d, -1 .* :n)
10×2 DataFrame
│ Row │ x │ n │
│ │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1 │ 1 │ 10 │
│ 2 │ 1 │ 9 │
│ 3 │ 2 │ 8 │
│ 4 │ 1 │ 7 │
│ 5 │ 1 │ 6 │
│ 6 │ 1 │ 5 │
│ 7 │ 2 │ 4 │
│ 8 │ 3 │ 3 │
│ 9 │ 3 │ 2 │
│ 10 │ 3 │ 1 │
10×3 DataFrame
Row │ x n c
│ Int64 Int64 String
─────┼──────────────────────
1 │ 1 10 j
2 │ 1 9 i
3 │ 2 8 h
4 │ 1 7 g
5 │ 1 6 f
6 │ 1 5 e
7 │ 2 4 d
8 │ 3 3 c
9 │ 3 2 b
10 │ 3 1 a
julia> @orderby(d, sortperm(:c, rev = true))
10×3 DataFrame
Row │ x n c
│ Int64 Int64 String
─────┼──────────────────────
1 │ 1 10 j
2 │ 1 9 i
3 │ 2 8 h
4 │ 1 7 g
5 │ 1 6 f
6 │ 1 5 e
7 │ 2 4 d
8 │ 3 3 c
9 │ 3 2 b
10 │ 3 1 a
julia> @orderby(d, :x, :n .- mean(:n))
10×2 DataFrame
Row │ x n
│ Int64 Int64
─────┼──────────────
│ 1 1 │ 5
│ 2 1 │ 6
│ 3 1 │ 7
│ 4 1 │ 9
│ 5 1 │ 10
│ 6 2 │ 4
│ 7 2 │ 8
│ 8 3 │ 1
│ 9 3 │ 2
10 │ 3 │ 3
```
10×3 DataFrame
Row │ x n c
│ Int64 Int64 String
─────┼──────────────────────
11 5 e
21 6 f
31 7 g
41 9 i
51 10 j
62 4 d
72 8 h
83 1 a
93 2 b
10 3 3 c
"""
macro orderby(d, args...)
esc(orderby_helper(d, args...))
Expand Down

0 comments on commit bd4b531

Please sign in to comment.