Description Usage Arguments Value Author(s) References See Also Examples
Creates a new environment for quick hash style dictionary lookup.
1 | hash(x, mode.out = "numeric")
|
x |
A two column dataframe. |
mode.out |
The type of output (column 2) expected
(e.g. |
Creates a "hash table" or a two column data frame in its own environment.
Bryan Goodrich and Tyler Rinker <tyler.rinker@gmail.com>.
http://www.talkstats.com/showthread.php/22754-Create-a-fast-dictionary
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | (DF <- aggregate(mpg~as.character(carb), mtcars, mean))
new.hash <- hash(DF) #numeric outcome
sapply(as.character(mtcars$carb), function(x) {
if(exists(x, envir = new.hash)) {
get(x, envir = new.hash)
} else {
NA
}
})
new.hash <- hash(DF, "character") #character outcome
sapply(as.character(mtcars$carb), function(x) {
if(exists(x, envir = new.hash)) {
get(x, envir = new.hash)
} else {
NA
}
})
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.