---
title: "Comment by Jeremy Miles on \"Hash tables in R\" | Hashnode"
description: "Is there a reason you prefer to use a new.env() rather than a list (which is how I would have done it)?"
url: "https://hashnode.com/posts/hash-tables-in-r/64f4cd3b8381fda8931f8fa8/comment/64f66ef0f6310e9375f96b86"
---

[Discussion](https://hashnode.com/posts/hash-tables-in-r/64f4cd3b8381fda8931f8fa8)

Comment [Hash tables in R](https://hashnode.com/posts/hash-tables-in-r/64f4cd3b8381fda8931f8fa8)

[Jeremy Miles](https://hashnode.com/@jeremymiles)

[Sep 4, 2023](https://hashnode.com/posts/hash-tables-in-r/64f4cd3b8381fda8931f8fa8/comment/64f66ef0f6310e9375f96b86)

Is there a reason you prefer to use a new.env() rather than a list (which is how I would have done it)?

[Chris Chapman](https://hashnode.com/@chrischapman)

[Sep 5, 2023](https://hashnode.com/posts/hash-tables-in-r/64f4cd3b8381fda8931f8fa8/comment/64f66ef0f6310e9375f96b86#reply-64f68b97f6310e9375f96cb7)

Great question, and good to hear from you! Lists and environments are extremely similar (thanks to the functional, Scheme-like nature of R) so either should be possible. If I get a chance, I'll see how much difference appears when written with lists.

IMO environments are a slightly better match for hash tables because they are exactly hashed in their implementation and unordered (whereas lists have sequential elements) and they work by reference (instead of copying on change, thus can be performance enhancing). I'm not sure whether there are different scale issues vs. lists, but wouldn't expect any (because of the underlying Scheme-like nature, as above).

Still, the old joke about economists applies to most things in R: if you ask a question of 4 R experts, you'll get 5 different answers :)

[Chris Chapman](https://hashnode.com/@chrischapman)

[Sep 5, 2023](https://hashnode.com/posts/hash-tables-in-r/64f4cd3b8381fda8931f8fa8/comment/64f66ef0f6310e9375f96b86#reply-64f7946bc035cd988c3210ed)

Looking to see if anyone has compared these, I found that Jeffrey Horner has: [jeffreyhorner.tumblr.com/post/114524915928/hash-t…](https://jeffreyhorner.tumblr.com/post/114524915928/hash-table-performance-in-r-part-i)

The takeaway from that is that environments (using their default behavior of being hash tables under the hood) are substantially more efficient.

Environments/hashes have nearly constant speed (close to O(1)) as the size grows, but lists take linearly increasing time (close to O(n)) for lookups.
