Friday, 14 September 2018

Basic calculations: Logical operators in R Languages

Logical Operators and Comparisons

The following table shows the operations and functions for logical comparisons (True or False).




Examples :

> x = 1 : 6       # Generates x=1,2,3,4,5,6
> (x > 2) & (x < 5)  # Checks whether the values are greater than 2 and less than 5

[1]  FALSE  FALSE  TRUE  TRUE  FALSE  FALSE

> x [(x > 2) & (x < 5)]  # Finds which values are greater than 2 and smaller than 5.
[1]   3  4



Logical Operators and Comparisons 



  • The shoter form performs element-wise comparisons in almost the same way as arithmetic operators.
  • The longer from evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined.
Example of   " The longer form evaluates left to right examining only the first element of each vector"
> x = 1 : 6           # Generates x = 1,2,3,4,5,6

> (x > 2)  && (x < 5) 
 [1]  FALSE

is equivalent to:

> (x[1] > 2) & (x[1] < 5)
  [1]  FALSE


Note that x[1] is only the first element in x.

> x[ (x > 2) && (x < 5) ] 
   integer(0)                # Finds which values are greater than 2 and smaller than 5
This statement is equivalent to 

> x [ (x[1] > 2) & (x[1] < 5) ]
integer (0)


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 (203) Cybersecurity (24) data management (11) Data Science (107) 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 (25) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (50) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (897) 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