# Data management: Sequence in R Language

Sequences

A sequence is a set of related numbers, events, movements, or items that follow each other in a particular order.

The regular sequences can be generate in R.

Syntax :-
seq ( )

seq (from = 1, to = 1, by = ( ( to from) / (length.out - 1) ), length.out = NULL, along.with = NULL, ...)

Help for seq

> help ("seq")

The default increment is +1 or -1

> seq (from = 2, to = 4)
  2  3  4

> seq (from = 4, to = 2)
  4  3  2

>seq (from = -4, to = 4)
  -4  -3  -2  -1  0  1  2  3  4

Sequence with constant increment:

Generate a sequence from 10 to 20 with an increment of 2 units

> seq (from = 10, to = 20 , by = 2)
  10  12  14  16  18  20

Generate a sequence from 20 to 10 with a decrement of 2 units

> seq (from = 20, to = 10, by = -2)
  20  18  16  14  12  10

Downstream sequence with constant increment:

Generate a sequence from 3 to -2 with a decrement of 0.5 units

> seq (from = 3, to = -2, by = -0.5)
  3.0  2.5  2.0  1.5  1.0  0.5  0.0  -0.5  -1.0  -1.5  -2

Sequence with a predefined length with default increment +1

> seq (to = 10, length = 10)
  1  2 3 4  5  6  7  8  9  10

Sequence with predefined length with constant fractional increment.

> seq (from = 10, length = 10, by = 0.1)
  10.0  10.1  10.2  10.3  10.4  10.5  10.6  10.7  10.8  10.9

Sequence with a predefined length with constant decrement

> seq (from = 10, length = 10, by = -2)
  10  8  6  4  2  0  -2  -4  -6  -8

Sequences with a predefined length with constant fractional decrement

> seq (from = 10, length = 5, by = -.2)
  10.0  9.8  9.6  9.4  9.2

Sequence with a predefined variable and constant increment

> x <-2
> seq (1, x, x/10)
  1.0  1.2  1.4  1.6  1.8  2.0

> x<-50
> seq (0, x, x/10)
  0  5  10  15  20  25  30  35  40  45  50  