Complete tutorial on using ‘apply’ functions in R