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: vignettes/datatable-joins.Rmd
+38-18Lines changed: 38 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -703,44 +703,64 @@ Products[!"popcorn",
703
703
The `:=` operator in `data.table` is used for updating or adding columns by reference. This means it modifies the original `data.table` without creating a copy, which is very memory-efficient, especially for large datasets. When used inside a `data.table`, `:=` allows you to **add new columns** or **modify existing ones** as part of your query.
704
704
705
705
#### Let's update our `Products` table with the latest price from `ProductPriceHistory`:
706
-
```{rSimple One-to-One Update}
706
+
```{rSimple_One_to_One_Update}
707
707
Products[ProductPriceHistory, on = .(id = product_id), price := i.price]
708
708
```
709
-
- The price column in Products is updated using the price column from ProductPriceHistory.
710
-
- The on = .(id = product_id) ensures that updates happen based on matching IDs.
711
-
- This method modifies Products in place, avoiding unnecessary copies.
709
+
- The `price` column in `Products` is updated using the `price` column from `ProductPriceHistory`.
710
+
- The `on = .(id = product_id)` ensures that updates happen based on matching IDs.
711
+
- This method modifies `Products` in place, avoiding unnecessary copies.
712
712
713
713
#### If we need to get the latest price and date (instead of all matches), we can still use := efficiently:
0 commit comments