hash(x)hash_look(terms, key, missing = NA)terms %hl% keyterms %hl+% keyhash_e(x, mode.out = "numeric")
"character"
, "numeric"
, etc.)hash
- Creates a "hash table", a two column data.table.
hash_e
- Creates a "hash table", a two column data.frame
in its own environment.
hash
- Creates a data.table
based hash table for quick hash style dictionary lookup.
hash_look
- Works with a hash table such as is returned from
hash
, to lookup values.
%hl%
- A binary operator version of hash_look
.
%hl+%
- A binary operator version of hash_look
for when missing
is assumed to be NULL
.
hash_e
- Creates a new environment for quick hash style dictionary lookup.
##===================## ## data.table Hashes ## ##===================## (DF <- aggregate(mpg~as.character(carb), mtcars, mean))as.character(carb) mpg 1 1 25.34286 2 2 22.40000 3 3 16.30000 4 4 15.79000 5 6 19.70000 6 8 15.00000x <- sample(DF[, 1], 20, TRUE) new.hash <- hash(DF) x2 <- c(9, 12, x) hash_look(x, new.hash)[1] 15.00000 15.79000 15.79000 16.30000 16.30000 19.70000 19.70000 19.70000 19.70000 15.79000 22.40000 19.70000 22.40000 [14] 25.34286 15.79000 16.30000 16.30000 19.70000 15.00000 15.00000x %hl% new.hash[1] 15.00000 15.79000 15.79000 16.30000 16.30000 19.70000 19.70000 19.70000 19.70000 15.79000 22.40000 19.70000 22.40000 [14] 25.34286 15.79000 16.30000 16.30000 19.70000 15.00000 15.00000x2 %hl% new.hash[1] NA NA 15.00000 15.79000 15.79000 16.30000 16.30000 19.70000 19.70000 19.70000 19.70000 15.79000 22.40000 [14] 19.70000 22.40000 25.34286 15.79000 16.30000 16.30000 19.70000 15.00000 15.00000x2 %hl+% new.hash[1] 9.00000 12.00000 15.00000 15.79000 15.79000 16.30000 16.30000 19.70000 19.70000 19.70000 19.70000 15.79000 22.40000 [14] 19.70000 22.40000 25.34286 15.79000 16.30000 16.30000 19.70000 15.00000 15.00000## Create generic functions hfun <- function(x, ...) { hsh <- hash(x, ...) function(x, ...) hash_look(x, hsh, ...) } m <- hfun(DF) m(x)[1] 15.00000 15.79000 15.79000 16.30000 16.30000 19.70000 19.70000 19.70000 19.70000 15.79000 22.40000 19.70000 22.40000 [14] 25.34286 15.79000 16.30000 16.30000 19.70000 15.00000 15.00000##====================## ## Environment Hashes ## ##====================## new.hash2 <- hash_e(DF) x %hl% new.hash2[1] 15.00000 15.79000 15.79000 16.30000 16.30000 19.70000 19.70000 19.70000 19.70000 15.79000 22.40000 19.70000 22.40000 [14] 25.34286 15.79000 16.30000 16.30000 19.70000 15.00000 15.00000x2 %hl% new.hash2[1] NA NA 15.00000 15.79000 15.79000 16.30000 16.30000 19.70000 19.70000 19.70000 19.70000 15.79000 22.40000 [14] 19.70000 22.40000 25.34286 15.79000 16.30000 16.30000 19.70000 15.00000 15.00000x2 %hl+% new.hash2[1] 9.00000 12.00000 15.00000 15.79000 15.79000 16.30000 16.30000 19.70000 19.70000 19.70000 19.70000 15.79000 22.40000 [14] 19.70000 22.40000 25.34286 15.79000 16.30000 16.30000 19.70000 15.00000 15.00000