Speed Up Your Matrix Calculations in R with Apply Functions