A series of yes-no questions to predict yes-no outcomes
Unfortunately, without the two csv files, we are not able to test your code... Maybe if you could show us the profiler output (see the example in ?summaryRprof) on a few iterations, it would help. What I suspect is that it will show most of the time is wasted either in the lm fit, or in the write call. Here are suggestions to improve on both as potential issues:

Alternative to lm

Since you are doing simple linear regression, i.e. regression with a single variable, there is a closed-form solution for the R-squared and it is fast to compute with R's built-ins:

RSQ1 &lt;- function(x, y) {
   mx  &lt;- mean(x)
   my  &lt;- mean(y)
   mxy &lt;- mean(x * y)
   mxx &lt;- mean(x * x)
   myy &lt;- mean(y * y)
  (mxy - mx * my)^2 / (mxx - mx^2) / (myy - my^2)
}


Compare this with your implementation

RSQ2 &lt;- function(z) {
  linearMod &lt;- lm(y ~ x, data = z)
  ModSum &lt;- summary(linearMod)
  ModSum$r.squared
}


Here I test both functions assuming your Bin_Matrix has 1000 rows. Your mileage may differ depending on how many observations you really have, something your question does not yet provide:

n &lt;- 1000
z &lt;- data.frame(x = runif(n), y = runif(n))

RSQ1(z$x, z$y)
# [1] 0.0007529693
RSQ2(z)
# [1] 0.0007529693

library(microbenchmark)
microbenchmark(RSQ1(z$x, z$y), RSQ2(z))
# Unit: microseconds
#            expr      min        lq      mean    median        uq      max neval
#  RSQ1(z$x, z$y)  111.707  120.8345  146.3035  126.5945  143.2855  689.371   100
#         RSQ2(z) 2531.381 2554.2105 2883.7659 2626.9020 2966.8550 5103.368   100


Inefficient write

The way you are using write is inefficient in that every time it is called, it must open the file, move the filehandle all the way to the end, write a line, then close the file. If your R squared is improved upon very often, this could start adding up. You would gain by doing the following.


Before your for loop, open a filehandle: fh &lt;- open("RSQ.txt")
Make write append to the filehandle: write(toString(Perm_Best, nrows= 1), file = fh)  (notice, there is no need for append = TRUE anymore)
After the for loop, close the file handle: close(fh)


Can you please give these suggestions a try and let me know if it helps? If it doesn't, maybe provide the output of the profiler? I hope it helps, good luck!



P.S.: Regarding coding style, you might find this approach for computation  Bin_num a little easier on the eye; it should not have a significant speed impact:

idx &lt;- as.numeric(rawData[cnt, 1:8])
bm  &lt;- Bin_Matrix[, idx]
Bin_num &lt;- data.table(result = c(Bin_Matrix[, 15]),
                      numb   = colSums(2^(0:7) * t(bm)))