vapply() - specify your output!

Intermediate R for Finance

Dan Becker

Manager of Data Science Curriculum at Flatiron School

vapply()

args(vapply)
function (X, FUN, FUN.VALUE, ..., USE.NAMES = TRUE) 
NULL
vapply(stock_list, FUN = class, FUN.VALUE = character(1))
 stock_name      ticker       price   good_deal 
"character" "character"   "numeric"   "logical"
Intermediate R for Finance

Anonymous functions

vapply(stock_return, 
       FUN = function(x) {c(mean = mean(x), sd = sd(x))},
       FUN.VALUE = numeric(2))
           apple         ibm        micr
mean 0.002838389 0.001926806 0.002472939
sd   0.007157457 0.008130703 0.009943938
Intermediate R for Finance

Let's practice!

Intermediate R for Finance

Preparing Video For Download...