简体   繁体   中英

Differences between hash and lists in R

In R, I find lists to be useful structures (like dictionaries in Python). I stumbled upon the hash package which seems to provide very similar functionality.

Are there any practical differences between lists and hashes that make one more desirable than the other? (Other than lists are part of the base)

I hope this isn't too open ended, but not sure how to narrow the scope of this.

from the hash documentation:

PASS-BY REFERENCE. Environments and hashes are special objects in R because only one copy exists globally. When provide as an argument to a function, no local copy is made and any changes to the hash in the functions are reflected globally.

PERFORMANCE. Hashes are based on environments and are designed to be exceedingly fast using the environments internal hash table. For small data structures, a list will out-perform a hash in nearly every case. For larger data structure, ie >100-1000 key value pair the performance of the hash becomes faster. Much beyond that the performance of the hash far outperforms native lists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM