Rif | R If Statement - r - learn r - r programming

  • In R programming, decision making is most important part of programming.
  • If statements operate on length-one logical vectors.
 r if statement

Read Also


if (test_expression) 

Syntax Explanation:

  • test_expression: If the test_expression is TRUE, the statement gets executed. But if statement is FALSE, nothing will occur. And test_expression can be a logical or numeric vector, but only the first element is taken into consideration. In the case of numeric vector, zero is occupied as FALSE, rest as TRUE.
r programming if else statement

Read Also

Sample Code

x <- 5
if(x > 3)
   print("This is odd number")

Code Explanation

 r if code expln
  1. Here we declare the variable x value as “5”.
  2. In this statement, we check the value for the variable x =5 is greater than 3 (5>3), because if the condition is true the prints "This is odd number” statement.


 r if sample output
  1. Here the value of the variable “x” are greater than 3 so “if” condition will be satisfied and the output print statement will be executed.

Related Searches to Rif | R If Statement