Description Usage Arguments Value See Also Examples
Environment based hash table useful for large vector lookups.
terms %l% key.match
- A binary operator version of
lookup
for when key.match
is a data.frame or
named list.
1 2 3 |
terms |
A vector of terms to undergo a lookup. |
key.match |
Takes one of the following: (1) a two column data.frame of a match key and reassignment column, (2) a named list of vectors (Note: if data.frame or named list supplied no key reassign needed) or (3) a single vector match key. |
key.reassign |
A single reassignment vector supplied if key.match is not a two column data.frame/named list. |
missing |
Value to assign to terms not matching the
key.match. If set to |
Outputs A new vector with reassigned values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ## Not run:
## Supply a dataframe to key.match
lookup(1:5, data.frame(1:4, 11:14))
## Retain original values for missing
lookup(1:5, data.frame(1:4, 11:14), missing=NULL)
lookup(LETTERS[1:5], data.frame(LETTERS[1:5], 100:104))
key <- data.frame(x=1:2, y=c("A", "B"))
big.vec <- sample(1:2, 3000000, T)
out <- lookup(big.vec, key)
out[1:20]
## Supply a named list of vectors to key.match
codes <- list(A=c(1, 2, 4),
B = c(3, 5),
C = 7,
D = c(6, 8:10))
lookup(1:10, codes)
## Supply a single vector to key.match and key.assign
lookup(mtcars$carb, sort(unique(mtcars$carb)),
c('one', 'two', 'three', 'four', 'six', 'eight'))
lookup(mtcars$carb, sort(unique(mtcars$carb)),
seq(10, 60, by=10))
## %l%, a binarary operator version of lookup
1:5 %l% data.frame(1:4, 11:14)
1:10 %l% codes
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.