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
## Update a data set by values from another data set
449
449
450
-
`update!` updates a data set values by using values from a transaction data set. The function uses the given keys (`on = ...`) to select rows for updating. By default, the missing values in transaction data set wouldn't replace the values in the main data set, however, using `allowmissing = true` changes this behaviour. If there are multiple rows in the main data set which match the key(s), using `mode = :all` causes all of them to be updated, `mode = :missing` causes only the ones which are missing in the main data set to be updated, and `mode = fun` updates the values which calling `fun` on them returns `true`. If there are multiple rows in the transaction data set which match the key, only the last one (given `stable = true` is passed) will be used to update the main data set.
450
+
`update!` updates a data set values by using values from a transaction data set. The function uses the given keys (`on = ...`) to select rows for updating. By default, the missing values in transaction data set wouldn't replace the values in the main data set, however, using `allowmissing = true` changes this behaviour. If there are multiple rows in the main data set which match the key(s), using `mode = :all` causes all of them to be updated, `mode = :missings` causes only the ones which are missing in the main data set to be updated, and `mode = fun` updates the values which calling `fun` on them returns `true`. If there are multiple rows in the transaction data set which match the key, only the last one (given `stable = true` is passed) will be used to update the main data set.
451
+
452
+
By default, `update!` updates the old values by the new values from the transaction data set, however, user may pass any function via the `op` keyword argument to update the values in the main data set by the result of calling `op` on values on both data sets. In this case, `update!` updates values in the main data set by `op(old, new)`, where `old` is the value from the main data set and `new` is the value from the transaction data set.
451
453
452
454
The `update!` functions replace the main data set with the updated version, however, if a copy of the updated data set is required, the `update` function can be used instead.
Update a `Dataset` `dsmain` with another `Dataset` `dsupdate` based `on` given keys for matching rows,
1488
1488
and change the left `Dataset` after updating.
@@ -1498,8 +1498,9 @@ the order of selected observation from the right table.
1498
1498
- `on`: can be a single column name, a vector of column names or a vector of pairs of column names, known as keys that the update function will based on.
1499
1499
- `allowmissing`: is set to `false` by default, so `missing` values in `dsupdate` will not replace the values in `dsmain`;
1500
1500
change this to `true` can update `dsmain` using `missing` values in `dsupdate`.
1501
-
- `mode`: by default is set to `:missings`, means that only rows in `dsmain` with `missing` values will be updated.
1501
+
- `mode`: by default is set to `:missings` and when `op` is passed the default is set to `:all`, it means when `op` is not set only rows in `dsmain` with `missing` values will be updated.
1502
1502
changing it to `:all` means all matching rows based `on` keys will be updated. Otherwise a function can be passed as `mode` to update only observations which return true when `mode` call on them.
1503
+
- `op`: by default, `update!` replace the values in `dsmain` by the values from `dsupdate`, however, user can pass any binary function to `op` to replace the value in `dsmain` by `op(left_value, right_value)`, i.e. replace it by calling `op` on the old value and the new value.
1503
1504
$_JOINMAPFORMATSDOC
1504
1505
$_JOINTHREADSDOC
1505
1506
$_JOINMETHODDOCSORT
@@ -1552,12 +1553,33 @@ julia> update!(dsmain, dsupdate, on = [:group, :id], mode = :missings) # Only mi
0 commit comments