December 2017
Beginner to intermediate
470 pages
12h 29m
English
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, ...