Skip to Content
R Programming By Example
book

R Programming By Example

by Omar Trejo Navarro
December 2017
Beginner to intermediate
470 pages
12h 29m
English
Packt Publishing
Content preview from R Programming By Example

Using memoization or cache layers

If you have deterministic algorithms, every time you provide equal inputs, you should receive equal outputs, and if that's the case and the process to go from inputs to outputs is very time-consuming, you may use memoization or cache layers. The basic idea is that you store some copies of the inputs and outputs, and whenever an input is sent to a function, before computing the output, you check whether or not that specific input's output has been computed before. If it has, send that instead of doing all the work again. This means you should only be computing the output for each input once.

You should try to implement such a layer in the fibonacci_recursive() function we created at the beginning of this chapter ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Efficient R Programming

Efficient R Programming

Colin Gillespie, Robin Lovelace
R Programming

R Programming

Jared P. Lander

Publisher Resources

ISBN: 9781788292542Supplemental Content