Functional R
Apply functions
mapply
Use mapply to operate on each element of multiple vectors
find say we have monthly sales for two years and we want to find monthwise delta
mapply(function(x,y) x - y, year2,year1 ) [1] 2 4 6 8 10
lapply
Use lapply to operate on each element of a list and return a list lapply(mtcars$mpg,function(x) sqrt(x))
sapply
Use sapply to operate on each element of a list and return a vector sapply(mtcars$mpg,function(x) sqrt(x))
Vectorization : Replace a nested for loop with apply
Consider a nested looping example. For each element in list1, compare each element in list2, check if value exists and return 0 or 1 based on value exists
Lambda Expression
R useful functions
http://www.personality-project.org/r/r.commands.html