Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between hash and lists in R

Tags:

list

r

hash

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.

like image 307
Kyle Brandt Avatar asked Jun 02 '12 14:06

Kyle Brandt


1 Answers

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, i.e. >100-1000 key value pair the performance of the hash becomes faster. Much beyond that the performance of the hash far outperforms native lists.

like image 137
Fojtasek Avatar answered Oct 09 '22 03:10

Fojtasek