hash: Hash/Dictionary Lookup

Description Usage Arguments Value Author(s) References See Also Examples

Description

Creates a new environment for quick hash style dictionary lookup.

Usage

1
  hash(x, mode.out = "numeric")

Arguments

x

A two column dataframe.

mode.out

The type of output (column 2) expected (e.g. "character", "numeric", etc.)

Value

Creates a "hash table" or a two column data frame in its own environment.

Author(s)

Bryan Goodrich and Tyler Rinker <tyler.rinker@gmail.com>.

References

http://www.talkstats.com/showthread.php/22754-Create-a-fast-dictionary

See Also

lookup, environment

Examples

 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
    }
})

trinker/qdap2 documentation built on May 31, 2019, 9:47 p.m.