julia> using DataFrames

julia> df = DataFrame(a = 1:3)
3×1 DataFrame
 Row │ a
     │ Int64
─────┼───────
   1 │     1
   2 │     2
   3 │     3

julia> combine(df, :a => sum => :a_sum)
1×1 DataFrame
 Row │ a_sum
     │ Int64
─────┼───────
   1 │     6

julia> select(df, :a => sum => :a_sum)
3×1 DataFrame
 Row │ a_sum
     │ Int64
─────┼───────
   1 │     6
   2 │     6
   3 │     6

julia> df = DataFrame(x1 = 1:3, x2 = 4:6)
3×2 DataFrame
 Row │ x1     x2
     │ Int64  Int64
─────┼──────────────
   1 │     1      4
   2 │     2      5
   3 │     3      6

julia> combine(df, [:x1, :x2] .=> [sum minimum maximum])
1×6 DataFrame
 Row │ x1_sum  x2_sum  x1_minimum  x2_minimum  x1_maximum  x2_maximum
     │ Int64   Int64   Int64       Int64       Int64       Int64
─────┼────────────────────────────────────────────────────────────────
   1 │      6      15           1           4           3           6

julia> [:x1, :x2] .=> [sum minimum maximum]
2×3 Matrix{Pair{Symbol}}:
 :x1=>sum  :x1=>minimum  :x1=>maximum
 :x2=>sum  :x2=>minimum  :x2=>maximum

julia> df = DataFrame(key1 = ["a", "b", "a", "b"],
                             key2 = [1, 2, 1, 2],
                             value = 1:4)
4×3 DataFrame
 Row │ key1    key2   value
     │ String  Int64  Int64
─────┼──────────────────────
   1 │ a           1      1
   2 │ b           2      2
   3 │ a           1      3
   4 │ b           2      4

julia> gdf = groupby(df, [:key1, :key2])
GroupedDataFrame with 2 groups based on keys: key1, key2
First Group (2 rows): key1 = "a", key2 = 1
 Row │ key1    key2   value
     │ String  Int64  Int64
─────┼──────────────────────
   1 │ a           1      1
   2 │ a           1      3
⋮
Last Group (2 rows): key1 = "b", key2 = 2
 Row │ key1    key2   value
     │ String  Int64  Int64
─────┼──────────────────────
   1 │ b           2      2
   2 │ b           2      4

julia> gdf[("b", 2)]
2×3 SubDataFrame
 Row │ key1    key2   value
     │ String  Int64  Int64
─────┼──────────────────────
   1 │ b           2      2
   2 │ b           2      4

julia> combine(gdf, :value => sum)
2×3 DataFrame
 Row │ key1    key2   value_sum
     │ String  Int64  Int64
─────┼──────────────────────────
   1 │ a           1          4
   2 │ b           2          6

julia> select(gdf, :value => sum)
4×3 DataFrame
 Row │ key1    key2   value_sum
     │ String  Int64  Int64
─────┼──────────────────────────
   1 │ a           1          4
   2 │ b           2          6
   3 │ a           1          4
   4 │ b           2          6

julia> using CSV, DataFrames, DataFramesMeta, Chain,
             Dates, HTTP, Plots, Statistics

julia> input = "https://raw.githubusercontent.com/Rdatatable\
                /data.table/master/vignettes/flights14.csv"
"https://raw.githubusercontent.com/Rdatatable/data.table/master/vignettes/flights14.csv"

julia> flights = CSV.read(HTTP.get(input).body, DataFrame)
253316×11 DataFrame
    Row │ year   month  day    dep_delay  arr_delay  carrier  origin   dest     air_time  distance  hour
        │ Int64  Int64  Int64  Int64      Int64      String3  String3  String3  Int64     Int64     Int64
────────┼─────────────────────────────────────────────────────────────────────────────────────────────────
      1 │  2014      1      1         14         13  AA       JFK      LAX           359      2475      9
      2 │  2014      1      1         -3         13  AA       JFK      LAX           363      2475     11
      3 │  2014      1      1          2          9  AA       JFK      LAX           351      2475     19
      4 │  2014      1      1         -8        -26  AA       LGA      PBI           157      1035      7
      5 │  2014      1      1          2          1  AA       JFK      LAX           350      2475     13
      6 │  2014      1      1          4          0  AA       EWR      LAX           339      2454     18
      7 │  2014      1      1         -2        -18  AA       JFK      LAX           338      2475     21
      8 │  2014      1      1         -3        -14  AA       JFK      LAX           356      2475     15
      9 │  2014      1      1         -1        -17  AA       JFK      MIA           161      1089     15
   ⋮    │   ⋮      ⋮      ⋮        ⋮          ⋮         ⋮        ⋮        ⋮        ⋮         ⋮        ⋮
 253309 │  2014     10     31        427        393  UA       EWR      ORD           100       719     21
 253310 │  2014     10     31         10        -27  UA       EWR      LAX           326      2454     10
 253311 │  2014     10     31         18        -14  UA       EWR      LAS           291      2227     16
 253312 │  2014     10     31          1        -30  UA       LGA      IAH           201      1416     14
 253313 │  2014     10     31         -5        -14  UA       EWR      IAH           189      1400      8
 253314 │  2014     10     31         -8         16  MQ       LGA      RDU            83       431     11
 253315 │  2014     10     31         -4         15  MQ       LGA      DTW            75       502     11
 253316 │  2014     10     31         -5          1  MQ       LGA      SDF           110       659      8
                                                                                       253299 rows omitted

julia> select!(flights, :year, :month, :origin, :dest, :dep_delay)
253316×5 DataFrame
    Row │ year   month  origin   dest     dep_delay
        │ Int64  Int64  String3  String3  Int64
────────┼───────────────────────────────────────────
      1 │  2014      1  JFK      LAX             14
      2 │  2014      1  JFK      LAX             -3
      3 │  2014      1  JFK      LAX              2
      4 │  2014      1  LGA      PBI             -8
      5 │  2014      1  JFK      LAX              2
      6 │  2014      1  EWR      LAX              4
      7 │  2014      1  JFK      LAX             -2
      8 │  2014      1  JFK      LAX             -3
      9 │  2014      1  JFK      MIA             -1
   ⋮    │   ⋮      ⋮       ⋮        ⋮         ⋮
 253309 │  2014     10  EWR      ORD            427
 253310 │  2014     10  EWR      LAX             10
 253311 │  2014     10  EWR      LAS             18
 253312 │  2014     10  LGA      IAH              1
 253313 │  2014     10  EWR      IAH             -5
 253314 │  2014     10  LGA      RDU             -8
 253315 │  2014     10  LGA      DTW             -4
 253316 │  2014     10  LGA      SDF             -5
                                 253299 rows omitted

julia> @chain flights begin
           groupby(:month, sort = true)
           combine(:dep_delay => mean)
           transform(:month => ByRow(monthname) => :month_name)
           @aside show(sort(_, :dep_delay_mean))
           plot(_.month_name, _.dep_delay_mean, label = nothing,
                xlabel = "Month", ylabel = "Mean delay", xrotation = 15)
           savefig("../Figures/flights.pdf")
       end;
10×3 DataFrame
 Row │ month  dep_delay_mean  month_name
     │ Int64  Float64         String
─────┼───────────────────────────────────
   1 │     9         4.74279  September
   2 │    10         7.85055  October
   3 │     3         8.92726  March
   4 │     8        10.0125   August
   5 │     4        10.2431   April
   6 │     5        13.6842   May
   7 │     6        14.0849   June
   8 │     7        16.4631   July
   9 │     2        17.8099   February
  10 │     1        22.9576   January
julia> @chain flights begin
           groupby(:month, sort = true)
           @combine(:dep_delay_mean = mean(:dep_delay))
           @rtransform(:month_name = monthname(:month))
           @aside show(sort(_, :dep_delay_mean))
           plot(_.month_name, _.dep_delay_mean, label = nothing,
                xlabel = "Month", ylabel = "Mean delay", xrotation = 15)
           savefig("../Figures/flights.pdf")
       end;
10×3 DataFrame
 Row │ month  dep_delay_mean  month_name
     │ Int64  Float64         String
─────┼───────────────────────────────────
   1 │     9         4.74279  September
   2 │    10         7.85055  October
   3 │     3         8.92726  March
   4 │     8        10.0125   August
   5 │     4        10.2431   April
   6 │     5        13.6842   May
   7 │     6        14.0849   June
   8 │     7        16.4631   July
   9 │     2        17.8099   February
  10 │     1        22.9576   January
