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

Avoiding sending data structures with overheads

We know that operating on heavy data structures such as data frames should be avoided when possible, and here it seems that it's still possible to do just that. What if instead of passing our data frame, we extract the price_usd variable we're interested in and simply use that? That seems promising.

To accomplish this, at the top of the function, we not only filter for observations containing symbol we want, but we also extract the price_usd variable at that point. Now, we may send this lower-overhead data structure to our slightly modified the sma_from_position_2() function. It is simply modified to work with this vector instead of the full data frame:

sma_efficient_2 <- function(period, symbol, ...
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