dict_assign_key_values | R Documentation |
The reason for using dictionaries in the first place is performance. Although it is correct that you can use named vectors and lists for the task, the issue is that they are becoming quite slow and memory hungry with more data. Yet what many people don't know is that R has indeed an inbuilt dictionary data structure environments with the option hash = TRUE
dict_assign_key_values(
x,
value,
pos = -1,
envir = as.environment(pos),
inherits = FALSE,
immediate = TRUE
)
x |
key (character) |
value |
value (character) |
pos |
= -1 |
envir |
= as.environment(pos) |
inherits |
= FALSE |
immediate |
= TRUE |
https://blog.ephorie.de/hash-me-if-you-can
Environment hashed, that can be used as fast dictionary.
Florian Wagner florian.wagner@wagnius.ch
df <- data.frame(key = c("ch","se","de","it"),
value = c(41L,46L,49L,39L))
# initialize hash
hash = dict_init(nrow(df))
# Assign key and values
dict_assign_key_values(df$key, df$value, hash)
dict_get_values(c("ch", "it"), hash)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.