Skip to contents

Column bind multiple data.tables.

Usage

cbindlist(l)
  setcbindlist(l)

Arguments

l

list of data.tables to merge.

Details

Column bind only stacks input elements. Works like data.table, but takes list type on input. Zero-column tables in l are omitted. Tables in l should have matching row count; recycling of length-1 rows is not yet implemented. Indices of the input tables are transferred to the resulting table, as well as the key of the first keyed table.

Value

A new data.table based on the stacked objects.

For setcbindlist, columns in the output will be shared with the input, i.e., no copy is made.

Note

No attempt is made to deduplicate resulting names. If the result has any duplicate names, keys and indices are removed.

Examples

d1 = data.table(x=1:3, v1=1L, key="x")
d2 = data.table(y=3:1, v2=2L, key="y")
d3 = data.table(z=2:4, v3=3L)
cbindlist(list(d1, d2, d3))
#> Key: <x>
#>        x    v1     y    v2     z    v3
#>    <int> <int> <int> <int> <int> <int>
#> 1:     1     1     1     2     2     3
#> 2:     2     1     2     2     3     3
#> 3:     3     1     3     2     4     3
cbindlist(list(d1, d1))
#>        x    v1     x    v1
#>    <int> <int> <int> <int>
#> 1:     1     1     1     1
#> 2:     2     1     2     1
#> 3:     3     1     3     1
d4 = setcbindlist(list(d1))
d4[, v1:=2L]
#> Key: <x>
#>        x    v1
#>    <int> <int>
#> 1:     1     2
#> 2:     2     2
#> 3:     3     2
identical(d4, d1)
#> [1] TRUE