for
Ranges and vector iteration.
Syntax
for (i in 1:n) { ... } // for (x in v) { ... }Description
The range 1:5 includes 5 as well. for-in iterates through the elements of a vector in order.
Example
Loading editor…
Expected output
1 2 3
When to use?
Repetitive tasks (though vectorization is generally preferred in R).