Dictionary data structure in R

China☆狼群 提交于 2019-12-03 23:25:59

An R list can have named elements and so function as a dictionary structure. You can just do:

> names(foo)
[1] "a" "b" "c"

If you are looking for a dictionary structure you might also consider using the hash packages which provides a Python and Perl like dictionary/hash with the expected functions such as keys, so you can say:

keys(hash)

In terms of performance a list serves as a better dictionary than a hash for several hundred elements or fewer (<200) because of the cost of the hashing. The hash package is much better for very large dictionaries.

> names(foo)
[1] "a" "b" "c"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!