Skip to content

Commit f80b8d0

Browse files
committed
Update transpose.md
1 parent 07e00f5 commit f80b8d0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/src/man/transpose.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ julia> ds = Dataset(A_2018=1:4, A_2019=5:8, B_2017=9:12,
302302
julia> f(x) = replace(x, r"[A_B]"=>"")
303303
f (generic function with 1 method)
304304
305+
julia> # later we provide a simpler solution for this example
306+
305307
julia> dsA = transpose(groupby(ds, :ID), r"A", renamerowid = f, variable_name = "Year", renamecolid = x->"A");
306308
307309
julia> dsB = transpose(groupby(ds, :ID), r"B", renamerowid = f, variable_name = "Year", renamecolid = x->"B");
@@ -405,6 +407,44 @@ julia> transpose(groupby(ds, 1), (:count, :weight),
405407
2 │ 1 3 4 0.2 0.3
406408
3 │ 2 3 4 0.2 0.2
407409
410+
julia> ds = Dataset(A_2018=1:4, A_2019=5:8, B_2017=9:12,
411+
B_2018=9:12, B_2019 = [missing,13,14,15],
412+
ID = [1,2,3,4])
413+
4×6 Dataset
414+
Row │ A_2018 A_2019 B_2017 B_2018 B_2019 ID
415+
│ identity identity identity identity identity identity
416+
│ Int64? Int64? Int64? Int64? Int64? Int64?
417+
─────┼────────────────────────────────────────────────────────────
418+
1 │ 1 5 9 9 missing 1
419+
2 │ 2 6 10 10 13 2
420+
3 │ 3 7 11 11 14 3
421+
4 │ 4 8 12 12 15 4
422+
423+
julia> f(x) = replace(x, r"[A_B]"=>"")
424+
f (generic function with 1 method)
425+
426+
julia> transpose(gatherby(ds, :ID), ([4,5,3], [1,2]),
427+
variable_name = [:year, nothing],
428+
renamerowid = f,
429+
renamecolid = (x,y)->y[1][1:1])
430+
12×4 Dataset
431+
Row │ ID year B A
432+
│ identity identity identity identity
433+
│ Int64? String? Int64? Int64?
434+
─────┼────────────────────────────────────────
435+
1 │ 1 2018 9 1
436+
2 │ 1 2019 missing 5
437+
3 │ 1 2017 9 missing
438+
4 │ 2 2018 10 2
439+
5 │ 2 2019 13 6
440+
6 │ 2 2017 10 missing
441+
7 │ 3 2018 11 3
442+
8 │ 3 2019 14 7
443+
9 │ 3 2017 11 missing
444+
10 │ 4 2018 12 4
445+
11 │ 4 2019 15 8
446+
12 │ 4 2017 12 missing
447+
408448
julia> ds = Dataset(rand(1:10, 2, 6), :auto)
409449
2×6 Dataset
410450
Row │ x1 x2 x3 x4 x5 x6

0 commit comments

Comments
 (0)