Monday, 17 September 2018

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)
     [1]  2  3  4

> seq (from = 4, to = 2)
    [1]  4  3  2

>seq (from = -4, to = 4)
   [1]  -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)
   [1]  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)
  [1]  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)
  [1]  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]  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)
  [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)
  [1]  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)
  [1]  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]  1.0  1.2  1.4  1.6  1.8  2.0

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




0 Comments:

Post a Comment

Codecademy Code Foundations

Popular Posts

Categories

Android (23) AngularJS (1) Assembly Language (2) Books (11) C (75) C# (12) C++ (81) Course (3) Data Science (1) Data Strucures (4) Downloads (1) Engineering (13) flutter (1) FPL (17) Hadoop (1) HTML&CSS (40) IS (25) Java (89) Leet Code (4) Pandas (2) PHP (20) Projects (19) Python (435) R (69) Selenium Webdriver (2) Software (14) SQL (27)