| hash | R Documentation |
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.
hash(x)
hash_look(terms, key, missing = NA)
terms %hl% key
terms %hl+% key
hash_e(x, mode.out = "numeric")
x |
A two column dataframe. |
terms |
A vector of terms to undergo a lookup. |
key |
The hash key to use. |
missing |
Value to assign to terms not found in the hash table. |
mode.out |
The type of output (column 2) expected (e.g.,
|
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_e - Bryan Goodrich and Tyler Rinker <tyler.rinker@gmail.com>.
https://www.talkstats.com/showthread.php/22754-Create-a-fast-dictionary
setDT,
hash
environment
##===================##
## data.table Hashes ##
##===================##
(DF <- aggregate(mpg~as.character(carb), mtcars, mean))
x <- sample(DF[, 1], 20, TRUE)
new.hash <- hash(DF)
x2 <- c(9, 12, x)
hash_look(x, new.hash)
x %hl% new.hash
x2 %hl% new.hash
x2 %hl+% new.hash
## Create generic functions
hfun <- function(x, ...) {
hsh <- hash(x, ...)
function(x, ...) hash_look(x, hsh, ...)
}
m <- hfun(DF)
m(x)
##====================##
## Environment Hashes ##
##====================##
new.hash2 <- hash_e(DF)
x %hl% new.hash2
x2 %hl% new.hash2
x2 %hl+% new.hash2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.