Use Environments for Lookup Tables

If you need to store a big lookup table, consider implementing the table using an environment. Environment objects are implemented using hash tables. Vectors and lists are not. This means that looking up a value in a vector with n elements or a list can take O(n) time. Looking up the value in an environment object takes O(1) time (on average).

To make it less awkward, consider defining an S4 class that implements the interface for the lookup table.

Get R in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.