Some key ways to generally improve the efficiency of your code:
Use lapply or Reduce instead of for loops where possible.
Use data.tables instead of data.frames and take advantage of their speedy vectorized transformations.
Consider parallelizing steps across multiple cores for speed boosts (e.g. via the parallel package). I'll leave it to you to decide whether (and where) you'd like to implement this.
Some key ways to generally improve the efficiency of your code:
lapply
orReduce
instead offor
loops where possible.data.table
s instead ofdata.frame
s and take advantage of their speedy vectorized transformations.parallel
package). I'll leave it to you to decide whether (and where) you'd like to implement this.