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

Popular Posts

Categories

AI (33) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (21) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (893) Python Coding Challenge (285) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses