R If Else | R If Else Statement - r - learn r - r programming
- This can be achieved in R programming using the conditional if-else statement.
- If-else returns a value with the same condition as test which is filled with elements selected from either yes or no depending on whether the element of test is TRUE or FALSE.
Read Also
Syntax
Syntax Explanation:
- test_expression: If the test_expression is TRUE, the statement gets executed. But if statement is FALSE, nothing will occur.
- else: Here else part is an optional. It is evaluated if test_expression is FALSE. The else must be in the same line as the closing braces of the if statements.
Sample Code
Read Also
Code Explanation
- Here we declare the variable x value as “5”.
- In this statement we check the condition that “x” value is greater than “2”, if condition satisfies it prints "This is even number”. If the condition is FALSE, its go to else statement.
Read Also
Output
- Here in this output we enter a value of the variable x= 5 so the given number is greater than “2” so the “if” section will be executed by displaying the output as “This is even number”.