Combination of set* functions provided by data.table. This is memeroy efficient because no copy is made at all.

set_in_dt(.data, ...)

set_mutate(.data, ..., by = NULL)

set_arrange(.data, ..., cols = NULL, order = 1L)

set_rename(.data, ...)

set_relocate(.data, ..., how = "first", where = NULL)

set_add_count(.data, ..., .name = "n")

set_replace_na(.data, ..., to)

set_fill_na(.data, ..., direction = "down")

Arguments

.data

A data.table

...

For set_in_dt: Receive '[i,j,by]' in data.table syntax. See in_dt. For set_mutate: List of variables or name-value pairs of summary/modifications functions. See mutate_dt. For set_arrange: Arrange by what group? Minus means descending order. See arrange_dt. For set_rename: List of variables or name-value pairs of summary/modifications functions. See rename_dt. For set_relocate: Columns to move. See relocate_dt For set_add_count: Variables to group by. See add_count_dt For set_replace_na and set_fill_na: Colunms to be replaced or filled. If not specified, use all columns. See fill_na_dt

by

Mutate by which group(s)?

cols

For set_arrange:A character vector of column names of x by which to order. If present, override .... Defaults to NULL.

order

For set_arrange:An integer vector with only possible values of 1 and -1, corresponding to ascending and descending order. Defaults to 1.

how

For set_relocate:The mode of movement, including "first","last","after","before". Default uses "first".

where

For set_relocate:Destination of columns selected by .... Applicable for "after" and "before" mode.

.name

For set_add_count: Character. Name of resulting variable. Default uses "n".

to

What value should NA replace by?

direction

Direction in which to fill missing values. Currently either "down" (the default) or "up".

Value

The input is modified by reference, and returned (invisibly) so it can be used in compound statements.

Details

These are a set of functions for modification on data.table by reference. They follow the same syntax of similar tidyfst functions. They do not return the result and considered to be memory efficient.

See also

Examples

library(pryr)
#> Registered S3 method overwritten by 'pryr': #> method from #> print.bytes Rcpp
rm(list = ls()) nr_of_rows <- 1e5 df <- data.table( Logical = sample(c(TRUE, FALSE, NA), prob = c(0.85, 0.1, 0.05), nr_of_rows, replace = TRUE) ) mem_change(mutate_dt(df,one = 1) -> res)
#> 1.22 MB
# makes no copy, update on "df" directly mem_change(set_mutate(df,one = 1))
#> 821 kB
all.equal(res,df)
#> [1] TRUE