Skip to content

Commit f68c6bc

Browse files
committed
added examples for cbind and mergelist
1 parent 67670e9 commit f68c6bc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

NEWS.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,41 @@
5050

5151
12. New `cbindlist()` and `setcbindlist()` for concatenating a `list` of data.tables column-wise, evocative of the analogous `do.call(rbind, l)` <-> `rbindlist(l)`, [#2576](https://github.com/Rdatatable/data.table/issues/2576). `setcbindlist()` does so without making any copies. Thanks @MichaelChirico for the FR, @jangorecki for the PR, and @MichaelChirico for extensive reviews and fine-tuning.
5252

53+
```r
54+
l = list(
55+
data.table(id = 1:3, a = letters[1:3]),
56+
data.table(b = 4:6, c = 7:9)
57+
)
58+
cbindlist(l)
59+
# id a b c
60+
# 1: 1 a 4 7
61+
# 2: 2 b 5 8
62+
# 3: 3 c 6 9
63+
```
64+
5365
13. New `mergelist()` and `setmergelist()` similarly work _a la_ `Reduce()` to recursively merge a `list` of data.tables, [#599](https://github.com/Rdatatable/data.table/issues/599). Different join modes (_left_, _inner_, _full_, _right_, _semi_, _anti_, and _cross_) are supported through the `how` argument; duplicate handling goes through the `mult` argument. `setmergelist()` carefully avoids copies where one is not needed, e.g. in a 1:1 left join. Thanks Patrick Nicholson for the FR (in 2013!), @jangorecki for the PR, and @MichaelChirico for extensive reviews and fine-tuning.
5466

67+
```r
68+
l = list(
69+
data.table(id = c(1, 2, 3), x = c("a", "b", "c")),
70+
data.table(id = c(1, 2, 4), y = c("d", "e", "f")),
71+
data.table(id = c(1, 3, 4), z = c("g", "h", "i"))
72+
)
73+
74+
# Recursive inner join
75+
mergelist(l, on = "id", how = "inner")
76+
# id x y z
77+
# 1: 1 a d g
78+
79+
# Recursive full outer join
80+
mergelist(l, on = "id", how = "full")
81+
# id x y z
82+
# 1: 1 a d g
83+
# 2: 2 b e <NA>
84+
# 3: 3 c <NA> h
85+
# 4: 4 <NA> f i
86+
```
87+
5588
### BUG FIXES
5689

5790
1. `fread()` no longer warns on certain systems on R 4.5.0+ where the file owner can't be resolved, [#6918](https://github.com/Rdatatable/data.table/issues/6918). Thanks @ProfFancyPants for the report and PR.

0 commit comments

Comments
 (0)