You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/man/reshaping_and_pivoting.md
+24-9Lines changed: 24 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,9 @@ julia> last(d, 6)
58
58
│ 6 │ Iris-virginica │ PetalWidth │ 1.8 │
59
59
```
60
60
61
-
The second optional argument to `stack` indicates the columns to be stacked. These are normally referred to as the measured variables. Column names can also be given:
61
+
The second optional argument to `stack` indicates the columns to be stacked.
62
+
These are normally referred to as the measured variables. Column names can also
63
+
be given:
62
64
63
65
```jldoctest reshape
64
66
julia> d = stack(iris, [:SepalLength, :SepalWidth, :PetalLength, :PetalWidth]);
@@ -88,11 +90,18 @@ julia> last(d, 6)
88
90
│ 6 │ Iris-virginica │ PetalWidth │ 1.8 │
89
91
```
90
92
91
-
Note that all columns can be of different types. Type promotion follows the rules of `vcat`.
93
+
Note that all columns can be of different types. Type promotion follows the
94
+
rules of `vcat`.
92
95
93
-
The stacked `DataFrame` that results includes all of the columns not specified to be stacked. These are repeated for each stacked column. These are normally refered to as identifier (id) columns. In addition to the id columns, two additional columns labeled `:variable` and `:values` contain the column identifier and the stacked columns.
96
+
The stacked `DataFrame` that results includes all of the columns not specified
97
+
to be stacked. These are repeated for each stacked column. These are normally
98
+
refered to as identifier (id) columns. In addition to the id columns, two
99
+
additional columns labeled `:variable` and `:values` contain the column
100
+
identifier and the stacked columns.
94
101
95
-
A third optional argument to `stack` represents the id columns that are repeated. This makes it easier to specify which variables you want included in the long format:
102
+
A third optional argument to `stack` represents the id columns that are
103
+
repeated. This makes it easier to specify which variables you want included in
104
+
the long format:
96
105
97
106
```jldoctest reshape
98
107
julia> d = stack(iris, [:SepalLength, :SepalWidth], :Species);
@@ -152,7 +161,9 @@ julia> last(d, 6)
152
161
│ 6 │ Iris-virginica │ PetalWidth │ 1.8 │
153
162
```
154
163
155
-
`unstack` converts from a long format to a wide format. The default is requires specifying which columns are an id variable, column variable names, and column values:
164
+
`unstack` converts from a long format to a wide format.
165
+
The default is requires specifying which columns are an id variable,
Passing `view=true` to `stack` returns a data frame whose columns are views into the original wide data frame. Here is an example:
311
+
Passing `view=true` to `stack` returns a data frame whose columns are views into
312
+
the original wide data frame. Here is an example:
300
313
301
314
```jldoctest reshape
302
315
julia> d = stack(iris, view=true);
@@ -337,7 +350,9 @@ This is provides a view of the original columns stacked together.
337
350
Id columns -- `RepeatedVector`
338
351
This repeats the original columns N times where N is the number of columns stacked.
339
352
340
-
None of these reshaping functions perform any aggregation. To do aggregation, use the split-apply-combine functions in combination with reshaping. Here is an example:
353
+
None of these reshaping functions perform any aggregation. To do aggregation,
354
+
use the split-apply-combine functions in combination with reshaping. Here is an
355
+
example:
341
356
342
357
```jldoctest reshape
343
358
julia> using Statistics
@@ -356,7 +371,7 @@ julia> first(d, 6)
356
371
│ 5 │ Iris-setosa │ SepalLength │ 5.0 │
357
372
│ 6 │ Iris-setosa │ SepalLength │ 5.4 │
358
373
359
-
julia> x = by(d, [:variable, :Species], :value => mean => :vsum);
374
+
julia> x = combine(groupby(d, [:variable, :Species]), :value => mean => :vsum);
0 commit comments