add_hash_column: add_hash_column

Description Usage Arguments Value Examples

Description

adds hash column (more info: digest). Hash is calculated on columne specified in 'colnames_for_hash' argument (all columns by default). Function may be useful for creating Primary Key column (e.g. in MySQL )

Usage

1
2
3
add_hash_column(DT_frame, hash_colname = "hash",
  colnames_for_hash = colnames(DT_frame), excluded_colnames = c(),
  unite = TRUE, cores = 1L, sort_colnames_for_hash = TRUE)

Arguments

DT_frame

data.table.

hash_colname

character; name of hash column

colnames_for_hash

character vector; column names to create hash

excluded_colnames

character vector; column names NOT to create hash

unite

logical; if TRUE, then firstly uses 'tidyr::unite_' on 'colnames_for_hash' and only then creates hash. It matter when data.table is big frame, because it is much faster

cores

integer; number of cores to create hash (works only when unite = TRUE); default: 1

sort_colnames_for_hash

logical; if TRUE, sorts columns alphabetically before hash creation

Value

data.table

Examples

1
2
3
4
data <- data.table(a = c("X", "y", "Z"), b = c("a", "a", "Aa"), c = c("q", "w", "e"))
dt_hash <- add_hash_column(data, colnames_for_hash = c("a", "b"),
                           excluded_colnames = c(), unite = TRUE, cores = 1L,
                           sort_colnames_for_hash = TRUE)

Tazovsky/utilities documentation built on May 8, 2019, 11:43 a.m.