3. Common Mathematical Operators in R
Operator/ function Meaning Example
+ Addition 4+5 is 9
- Substraction 4-5 is -1
* Multiplication 4*5 is 20
/ Division 4/5 is 0.8
^ Exponent 2^4 is 16
%% Modulus (Remainder from division) 15 %% 12 is 3
%/% Integer Division 15 %/% 12 is 1
4. logical operators -1
Operator/ function Meaning Example
== Is RHS equal to LHS? 5 == 2 will return FALSE
'Anil' == 'anil' is FALSE
!= Is RHS not equal to LHS? 'ABCD' != 'abcd' is TRUE
>= Is LHS greater than or equal to RHS? 5 >= 2 will return TRUE
<= Is LHS less than or equal to RHS? 15 <= 2 will return FALSE
> Is LHS strictly greater than RHS? 2 > 2 will return FALSE
5. logical operators -2
Operator/ function Meaning Example
< Is LHS strictly less than RHS? 12 < 12 will return FALSE
is.na() Whether the argument passed is NA is.na(NA) is TRUE
is.null() Whether the argument passed is
null
is.null(NA) is FALSE
| Logical OR TRUE | FALSE will return TRUE
& Logical AND TRUE & FALSE will return FALSE
! Logical NOT !TRUE will return FALSE
6. logical operators -3
Operator/ function Meaning Example
|| Element wise Logical OR Examines only the first element of
the operands resulting into a single
length logical vector
&& Element wise Logical AND Examines only the first element of
the operands resulting into a single
length logical vector
%in% LHS IN RHS Checks whether LHS elements are
present in RHS vector
7. Common arithmetical Functions
Function Meaning Input Output
sum() Adds all elements One or more Vector,
matrix, array
Vector having 1 element
only
prod() Returns product of all
elements
One or more Vector,
matrix, array
Vector having 1 element
only
mean() Returns the arithmetic
mean
One Vector, matrix, array Vector having 1 element
only
max() Returns maximum value One or more Vector,
matrix, array
Vector having 1 element
only
min() Returns minimum value One or more Vector,
matrix, array
Vector having 1 element
only
8. More arithmetical Functions
Function Meaning Input Output
ceiling() Returns integer(s) not less
than given values
One Vector, matrix, array Vector, matrix, array
having same dim
floor() Returns largest integers
not greater than given
values
One Vector, matrix, array Vector, matrix, array
having same dim
trunc() returns integers formed by
truncating the values
towards 0
One Vector, matrix, array Vector, matrix, array
having same dim
round(x, digits =
0)
Rounds the given value(s)
to number of decimal
places provided
One Vector, matrix, array Vector, matrix, array
having same dim
9. More arithmetical Functions
Function Meaning Input Output
signif(x, digits =
6)
Round to significant
digits
One Vector, matrix, array Vector, matrix, array
having same dim
factorial() Returns factorial One Vector, matrix, array
of integer type
Vector having 1 element
sqrt() Returns square root One Vector, matrix, array Vector, matrix, array
having same dim
log10() or log2() Logrithm with base 10 or 2
respectively
One Vector, matrix, array Vector, matrix, array
having same dim
exp(x) returns exponential One Vector, matrix, array Vector, matrix, array
having same dim
10. Some Statistical functions
Function Meaning Input Output
sd() Returns standard
deviation
One Vector, matrix, array Vector having 1 element
only
var() Returns variance One or more Vector,
matrix, array
Vector having 1 element
only
median() Returns median value One Vector, matrix, array Vector having 1 element
only
range() Returns range One Vector, matrix, array Vector having 2 elements
11. More Statistical functions
Function Meaning Input Output
IQR() Computes interquartile
range of the x values
One Vector, matrix, array Vector having 1 element
only
quantile() Computes percentile of
given values for the given
probabilities in probs
argument
One Vector, matrix, array Named Vector having 5
elements by default, OR
equal to the length of
probs vector given