Vectorising Instead of Looping
Vector operations are faster and shorter than loops.
Example
x <- 1:10
sq <- x ^ 2
print(sq)
print(sum(x[x %% 2 == 0]))
print(cumsum(x))
print(sapply(x, function(i) i * 2))Exercise
Running total.
(x)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.