Operators in R can be majorly classified into four broader categories.

Let’s understand them one by one.

`+ , - , * , / , %% , %/% , ^ , **`

are all arithmetic operators in R.

`+`

Operator is used for addition

`-`

Operator is used for subtraction

`*`

Operator is used for multiplication

`/`

Operator is used for division

`%%`

Operator is used to find the remainder

`%/%`

Operator is used to find the quotient

`^`

or `**`

Operator is used for finding the power of a number.

Let’s see some examples where these operators are used.

`+`

Arithmetic operator.`2 + 3`

`[1] 5`

`+`

Arithmetic operator.`12 + 15 + 23`

`[1] 50`

`+`

Arithmetic operator.`225 + 432 + 21`

`[1] 678`

`-`

Arithmetic operator.`3 - 2`

`[1] 1`

`-`

Arithmetic operator.`15 - 12 `

`[1] 3`

`23 * 32`

`[1] 736`

`223 * 192`

`[1] 42816`

`32 / 4`

`[1] 8`

`24364 / 4`

`[1] 6091`

`12 %% 5`

`[1] 2`

`231 %% 2`

`[1] 1`

`12 %/% 5`

`[1] 2`

`231 %/% 2`

`[1] 115`

`12^5`

`[1] 248832`

Alternate method,

`12**5`

`[1] 248832`

`22^3`

`[1] 10648`

Alternate method,

`22**3`

`[1] 10648`

`<-`

is the assignment operator in R. It is actually equivalent to equal to sign `=`

. In general, we say `a = 2`

, which means we are assigning a value 2 to a variable `a`

. In R, we write `a <- 2`

instead of `a = 2`

.

`b <- 15`

`c <- -25`

We use relational operators to check the relation between two or more variables. Below mentioned are some examples of relational operators which we use is R.

Assigning values to variable a and b as given in question.

```
a <- 5
b <- 3
```

Checking whether `a`

is less than `b`

or not.

`a < b `

`[1] FALSE`

Checking whether `a`

is greater than `b`

or not.

`a > b`

`[1] TRUE`

Checking whether `a`

is less or equal to `b`

or not.

`a <= b`

`[1] FALSE`

Checking whether `a`

is greater or equal to `b`

or not.

`a >= b`

`[1] TRUE`

Checking whether `a`

is equal to `b`

or not.

`a == b`

`[1] FALSE`

Checking whether `a`

is not equal to `b`

or not.

`a != b`

`[1] TRUE`

Now, let’s see the summary of what we have done in the below snapshot.

These operators are used to perform Boolean expression like `AND`

and `OR`

.

We use `&`

symbol for `AND`

and `|`

symbol for `OR`

.

1. a==5&b==3

2. a==4&b==3

3.a==4&b==2

4. a==5&b==2

5. a==5|b==3

6. a==4|b==3

7.a==4|b==2

8. a==5|b==2

Assigning values to variable a and b as given in question.

```
a <- 5
b <- 3
```

**Solution 1: Checking a==5&b==3**

a==5 will return a value `TRUE`

b==3 will also return a value `TRUE`

We know, `TRUE`

&`TRUE`

is `TRUE`

`a==5&b==3`

`[1] TRUE`

**Solution 2: Checking a==4&b==3**

a==4 will return a value `FALSE`

b==3 will also return a value `TRUE`

We know, `FALSE`

&`TRUE`

is `FALSE`

`a==4&b==3`

`[1] FALSE`

**Solution 3: Checking a==4&b==2**

a==4 will return a value `FALSE`

b==2 will also return a value `FALSE`

We know, `FALSE`

&`FALSE`

is `FALSE`

`a==4&b==2`

`[1] FALSE`

**Solution 4: Checking a==5&b==2**

a==4 will return a value `TRUE`

b==2 will also return a value `FALSE`

We know, `TRUE`

&`FALSE`

is `FALSE`

`a==5&b==2`

`[1] FALSE`

**Solution 5: Checking a==5|b==3**

a==5 will return a value `TRUE`

b==3 will also return a value `TRUE`

We know, `TRUE`

|`TRUE`

is `TRUE`

`a==5|b==3`

`[1] TRUE`

**Solution 6: Checking a==4&b==3**

a==4 will return a value `FALSE`

b==3 will also return a value `TRUE`

We know, `FALSE`

|`TRUE`

is `TRUE`

`a==4|b==3`

`[1] TRUE`

**Solution 7: Checking a==4&b==2**

a==4 will return a value `FALSE`

b==2 will also return a value `FALSE`

We know, `FALSE`

|`FALSE`

is `FALSE`

`a==4|b==2`

`[1] FALSE`

**Solution 8: Checking a==5|b==2**

a==4 will return a value `TRUE`

b==2 will also return a value `FALSE`

We know, `TRUE`

|`FALSE`

is `TRUE`

`a==5|b==2`

`[1] TRUE`

<<Previous | Next>> |
---|

© Copyright 2021

[RUHH ROBOTICS AUTHORS]

www.examsforwinners.com