R Programming: seq() Function

nick3499
1 min readJul 28, 2016

--

Use the seq() function to generate a sequence of numeric elements. Start the R interpreter in a Unix-like operating system. 0 is where the sequence begins, 1 is where it ends, and length.out sets the amount of numeric elements in the vector.

> seq(0,1,length.out = 17)
[1] 0.0000 0.0625 0.1250 0.1875 0.2500 0.3125 0.3750 0.4375 0.5000 0.5625
[11] 0.6250 0.6875 0.7500 0.8125 0.8750 0.9375 1.0000

To generate a sequence of 16ths of an inch, 17 needed to be used instead of 16, since the function starts at zero.

The by attribute is used for numeric incrementation. Below, incrementation of the sequence equates to π.

> seq(0, 31.5, by = pi)
[1] 0.000000 3.141593 6.283185 9.424778 12.566371 15.707963 18.849556
[8] 21.991149 25.132741 28.274334 31.415927

Notice how the sequence above ended at 31.415927 instead of 31.5.

Since the default value of by is 1, a simple sequence of numbers can be generated.

> seq(16)
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

--

--

nick3499
nick3499

Written by nick3499

coder of JavaScript and Python

No responses yet