1

Most of the books I've read about R recommend that one try to use "vector operations" like x and y are vectors of equal length:

x + y

instead of:

for (i in 1:length(x)){ x[i] + y[i] }

because x+y is suppose to be faster and walking through a for loop is not.

Why is that? how does this work and make it faster? as far as I can tell, R is only using one process and I can't understand why doing such a thing could be faster.

natorro
  • 2,793
  • 3
  • 19
  • 16
  • Your question is really about 2 things... The vectorized vs looping operations on one hand, and the idea of parrallel-processing on the other. I'd suggest editing it to focus on the first aspect, and making another whole new question about parrallel-processing. It's hard to answer it as it is now (that's why I deleted my answer... but I could undelete it if you really put the focus on vector vs looping). – Dominic Comtois Apr 14 '15 at 23:47

0 Answers0