The built-in setNames() function makes it easy to create a hash from given lists of keys and values. (Thanks to Nick K for the best offer.)
Usage: hh <- setNames(as.list(values), keys)
Example:
players <- c("bob", "tom", "tim", "tony", "tiny", "hubert", "herbert") rankings <- c(0.2027, 0.2187, 0.0378, 0.3334, 0.0161, 0.0555, 0.1357) league <- setNames(as.list(rankings), players)
Then accessing the values โโthrough the keys is easy:
league$bob [1] 0.2027 league$hubert [1] 0.0555
Assad Ebrahim Jul 08 '15 at 16:53 2015-07-08 16:53
source share