What are the different operators in R programming?
Operators are used to perform operations on variables and values.
In the example below, we use the + operator to add together two values:
Arithmatic Operator
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
^ Exponent x ^ y
%% Modulus (Remainder from division) x %% y
%/% Integer Division x%/%y
Comparision Operator
== Equal x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y Locgical Operators
& Element-wise Logical AND operator. It returns TRUE if both elements are TRUE
&& Logical AND operator - Returns TRUE if both statements are TRUE
| Elementwise- Logical OR operator. It returns TRUE if one of the statement is TRUE
|| Logical OR operator. It returns TRUE if one of the statement is TRUE.
! Logical NOT - returns FALSE if statement is TRUE Miscalleneous Operator
: Creates a series of numbers in a sequence x <- 1:10
%in% Find out if an element belongs to a vector x %in% y
%*% Matrix Multiplication x <- Matrix1 %*% Matrix2
What are math operators in python
Python math operators are something you are no doubt familiar with. You have been using them your entire life, and for the most part, they work in Python the same way you expect them to. The following are the operators you can use on numbers in Python:
+: The addition operator. You can perform addition with this operator.
-: The minus operator. You can perform subtractions with this operator.
*: The multiplication operator. You can perform multiplication with this operator.
/: The division operator. You can perform division with this operator.
**: The exponentiation operator. You can raise numbers to a power with this operator.
%: The modulus operator. You can use this to return the remainder from a division.
Some other built operators like
sum()
min()
max()
sqrt()
etc
Explain a few control statemnets in R?
Control statements are expressions used to control the execution and flow of the program based on the conditions provided in the statements. These structures are used to make a decision after assessing the variable. In this article, we’ll discuss all the control statements with the examples.
If Condition
This control structure checks the expression provided in parenthesis is true or not. If true, the execution of the statements in braces {} continues.
If else
It is similar to if condition but when the test expression in if condition fails, then statements in else condition are executed.
For loop
It is a type of loop or sequence of statements executed repeatedly until exit condition is reached.
While loop
while loop is another kind of loop iterated until a condition is satisfied. The testing expression is checked first before executing the body of loop.
Repeat Loop and break
repeat is a loop which can be iterated many number of times but there is no exit condition to come out from the loop. So, break statement is used to exit from the loop. break statement can be used in any type of loop to exit from the loop.