Skip to content

Commit f7263a3

Browse files
authored
added examples for cbindlist and mergelist (#7172)
* added examples for cbind and mergelist * updated examples * Update NEWS.md
1 parent d3f08f3 commit f7263a3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

NEWS.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,40 @@
8181

8282
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.
8383

84+
```r
85+
l = list(
86+
data.table(id = 1:3, a = letters[1:3]),
87+
data.table(b = 4:6, c = 7:9)
88+
)
89+
cbindlist(l)
90+
# id a b c
91+
# 1: 1 a 4 7
92+
# 2: 2 b 5 8
93+
# 3: 3 c 6 9
94+
```
95+
8496
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.
8597

98+
```r
99+
l = list(
100+
data.table(id = c(1L, 2L, 3L), x = c("a", "b", "c")),
101+
data.table(id = c(1L, 2L, 4L), y = c("d", "e", "f")),
102+
data.table(id = c(1L, 3L, 4L), z = c("g", "h", "i"))
103+
)
104+
105+
# Recursive inner join
106+
mergelist(l, on = "id", how = "inner")
107+
# id x y z
108+
# 1: 1 a d g
109+
110+
# Recursive left join (the default 'how')
111+
mergelist(l, on = "id", how = "left")
112+
# id x y z
113+
# 1: 1 a d g
114+
# 2: 2 b e <NA>
115+
# 3: 3 c <NA> h
116+
```
117+
86118
14. `fcoalesce()` and `setcoalesce()` gain `nan` argument to control whether `NaN` values should be treated as missing (`nan=NA`, the default) or non-missing (`nan=NaN`), [#4567](https://github.com/Rdatatable/data.table/issues/4567). This provides full compatibility with `nafill()` behavior. Thanks to @ethanbsmith for the feature request and @Mukulyadav2004 for the implementation.
87119

88120
15. New function `isoyear()` has been implemented as a complement to `isoweek()`, returning the ISO 8601 year corresponding to a given date, [#7154](https://github.com/Rdatatable/data.table/issues/7154). Thanks to @ben-schwen and @MichaelChirico for the suggestion and @venom1204 for the implementation.

0 commit comments

Comments
 (0)