How to create a dictionary / hash table by iterating through a column?

前端 未结 3 522
广开言路
广开言路 2020-12-29 10:35

I have a data frame of two columns: key and value and I would like to create a dictionary using the respective row of each column for each element of the dictionary / hash t

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 11:11

    Another option that is similar to what you've seen with Python or Perl is the hash package. See: http://cran.r-project.org/web/packages/hash/

    If your keys are particularly long, then I recommend storing two hash tables. First, hash the key, using the digest package and store a dictionary (hash table) that maps from digest to key (mapping from key to digest is already done by the digest package ;-)), and then from the digest to the value that you wish to store. This works very well for me.

提交回复
热议问题