Description Usage Arguments Details Value Examples
This function attempts to cbind two data.tables without making copies. Compared to cbind, this can result to up to 3X memory efficiency. By default, a 2X memory efficiency is minimal with frequent garbage collects.
1 |
dt1 |
Type: data.table. The data.table to combine on. |
dt2 |
Type: data.table. The data.table to "copy" on |
low_mem |
Type: boolean. Unallows |
collect |
Type: integer. Forces a garbage collect every |
silent |
Type: boolean. Force silence during garbage collection iterations at no speed cost. Defaults to |
Warning: dt1
and dt2
are pointers only even if you pass the objects to this function. This is how memory efficiency is achieved. dt1
gets overwritten on the fly.
A data.table based on dt1
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | library(data.table)
df1 <- data.frame(matrix(nrow = 50000, ncol = 1000))
df2 <- data.frame(matrix(nrow = 50000, ncol = 1000))
setDT(df1)
setDT(df2)
df1[is.na(df1)] <- 1
gc()
df2[is.na(df2)] <- 2
colnames(df1) <- paste("x", colnames(df1), sep = "")
gc() # look memory usage
# open a task manager to check current RAM usage
df1 <- DTcbind(df1, df2, low_mem = TRUE, collect = 20, silent = FALSE)
# check RAM usage in a task manager: it is identical to what we had previously!
gc() # gives no gain
df3 <- data.frame(matrix(nrow = 50000, ncol = 1000))
setDT(df3)
# look on task manager the current RAM usage
#df1 <- cbind(df1, df3) # RAM usage explodes!
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.