Skip to content

Commit 49a6c50

Browse files
committed
Update modify.md
1 parent 97bafe8 commit 49a6c50

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

docs/src/man/modify.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ The first argument of these two functions is the name of the data set which is g
1212

1313
> `modify!(ds, args...)` or `modify(ds, args...)`
1414
15-
The simplest form of `args` is `col => fun` which calls `fun` on `col` as a vector and replaces `col` with the output of the call. `col` can be a column index or a column name. Thus, to replace the value of a column which is called `:x1` in a data set `ds` with their standardised values, we can use the following expression:
15+
The simplest form of `args` is `col => fun` which calls `fun` on `col` as a vector and **replaces** `col` with the output of the call. `col` can be a column index or a column name. Thus, to replace the value of a column which is called `:x1` in a data set `ds` with their standardised values, we can use the following expression:
1616

1717
> `modify!(ds, :x1 => stdze)`
1818
19-
where `:x1` is a column in `ds`, and `stdze` is a function which subtracts values by their mean and divide them by their standard deviation. If you don't want to replace the column, but instead you like to create a new column based on calling `fun` on `col`, the `col => fun => :newname` (here `:newname` is a name for the new column) form is handy. Thus, to standardised the values of a column, which is called `:x1`, and store them as a new column in the data set, you can use,
19+
where `:x1` is a column in `ds`, and `stdze` is a function which subtracts values by their mean and divide them by their standard deviation. If you don't want to replace the column, but instead you like to create a new column based on calling `fun` on `col`, the `col => fun => :newname` (here `:newname` is a name for the new column) form is handy. Thus, to standardised the values of a column, which is called `:x1`, and store them as a new column in the data set, you can use,
2020

2121
> `modify!(ds, :x1 => stdze => :x1_stdze)`
2222
@@ -176,3 +176,29 @@ julia> modify!(sale, :customer => byrow(name_split),
176176
```
177177

178178
In the last example, we use `byrow` to apply `name_split` on each row of `:customer`, and since there is only one column as the input of `byrow`, `modify!` replaces the column with the new values. Also, note that the `modify!` function has access to these new values and we can use `splitter` to split the column into two new columns.
179+
180+
## Using `Tuple` of column names
181+
182+
When the form of the transform specifications is as `NTuple{col} => fun`, `modify!` and `modify` assumes that the `fun` function accepts multiple arguments (multiple columns).
183+
184+
```jldoctest
185+
julia> body = Dataset(weight = [78.5, 59, 80], height = [160, 171, 183])
186+
3×2 Dataset
187+
Row │ weight height
188+
│ identity identity
189+
│ Float64? Int64?
190+
─────┼────────────────────
191+
1 │ 78.5 160
192+
2 │ 59.0 171
193+
3 │ 80.0 183
194+
195+
julia> modify(body, (:weight, :height)=> cor)
196+
3×3 Dataset
197+
Row │ weight height cor_weight_height
198+
│ identity identity identity
199+
│ Float64? Int64? Float64?
200+
─────┼───────────────────────────────────────
201+
1 │ 78.5 160 0.0890411
202+
2 │ 59.0 171 0.0890411
203+
3 │ 80.0 183 0.0890411
204+
```

0 commit comments

Comments
 (0)