In roughly decreasing order of importance:
In R, this is stupid. R is designed to do all this in a single "vectorized" operation:for (i in 1:length(a)) { c[i] = a[i] + b[i] }
Since we need to add vectors all the time, this is an instance of using a single function repeatedly, rather than writing the same loop many times. (R just happens to call the function "+".) It is also orders of magnitude faster than the explicit loop, if the vectors are at all long. Wherever possible, vectorize your operations. (The apply() function and its relatives are your friends.) With practice, this gets easier and more natural.c = a + b