R Language Sequence of numbers


Example

Use the : operator to create sequences of numbers, such as for use in vectorizing larger chunks of your code:

x <- 1:5
x
## [1] 1 2 3 4 5

This works both ways

10:4
# [1] 10  9  8  7  6  5  4

and even with floating point numbers

1.25:5
# [1] 1.25 2.25 3.25 4.25

or negatives

-4:4
#[1] -4 -3 -2 -1  0  1  2  3  4