Description Usage Arguments Value See Also Examples
This function creates an xhash
object, extended version of
hash
.
While hash
accepts only strings as indices, xhash
can deal with generic index variables, termed as "state".
1 2 |
convfunc |
function that converts a state to a key.
It must take a positional argument |
convfunc_vec |
function for vectorized conversion from states to keys.
This function must receive a positional argument |
default_value |
value to be returned when a state is not recorded in the table. |
xhash
object
hash-ops, vectorized-hash-ops
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | h <- xhash(convfunc = function(state, ...) paste0(state, collapse='-'))
# insert
h[c(1, 2, 3)] <- 100
h[matrix(1:9, nrow=3, ncol=3)] <- -5
# retrieve
h[c(1, 2, 3)]
h[matrix(1:9, nrow=3, ncol=3)]
h[1:9] # equivalent as above, due to conversion to a same key
h[c(3, 2, 1)] # this is undefined
# delete
h[c(1, 2, 3)] <- NULL
# vectorized operations
## insert
setvalues(h, list(1:2, 1:3), c(9, 8))
## retrieve
getvalues(h, list(1:9, 1:2, 3:1))
## delete
setvalues(h, list(1:9, 1:3), NULL)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.