Posts

Showing posts from October, 2017

Shortcuts to making your R code run faster! Part 2

Hello everyone! I am sorry it took me so long to write this next post. As in my last post you can see I have been dealing with a lot on my plate. However, I am excited to share some more R tips to making your code run faster and more efficiently. In this post we will be working with vectors and matrices. 1. Loose the loop between matrices.  How to run your code without a loop and using the apply()  function. Now I am only going to show you the basic form of this function. The apply function helps save lots of computation time and makes your code so much more cleaner. For example, lets say we have a matrix and we want to find the mean of each column. You can't just use the mean() function, because that will give you the mean of the whole matrix. And you can do it column by column, but that takes time so to automate it one would think to create a loop. # Example of loop of calculations done on a column. m <- matrix ( c ( 1 : 100000 ), nrow = 20 ) MeanCol = n