Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
R High Performance Programming

You're reading from  R High Performance Programming

Product type Book
Published in Jan 2015
Publisher
ISBN-13 9781783989263
Pages 176 pages
Edition 1st Edition
Languages

Table of Contents (17) Chapters

R High Performance Programming
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Understanding R's Performance – Why Are R Programs Sometimes Slow? Profiling – Measuring Code's Performance Simple Tweaks to Make R Run Faster Using Compiled Code for Greater Speed Using GPUs to Run R Even Faster Simple Tweaks to Use Less RAM Processing Large Datasets with Limited RAM Multiplying Performance with Parallel Computing Offloading Data Processing to Database Systems R and Big Data Index

Use of hash tables for frequent lookups on large data


One common task in data analysis is data lookup, which is often implemented via a list in R. For example, to look up customers' ages, we can define a list, say, cust_age, with values set to customer ages and names set to the corresponding customer names (or IDs), that is names(cust_age) <- cust_name. In this case, to look up John Doe's age, the following can be called: cust_age[["John_Doe"]]. However, the implementation of lists in R is not optimized for lookup; it incurs O(N) time complexity to perform a lookup on a list of N elements. This means that the values indexed later in the list require more time to look up. As N grows, this effect gets stronger. When a program requires frequent lookups, the cumulative effect can be significant. An alternative to lists that offers a more optimized data lookup is a hash table. In R, this is available from the CRAN package hash. A hash table's lookup incurs O(1) time complexity.

The next code...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}