R Decision Making Statements

R Tutorial – We shall learn R decision making statements provided by R programming language to incorporate decision making in R code.

R Decision Making

Decision making is an important aspect in any programming language. It helps to take a different path in the code based on the dynamic results. This helps a lot in process automation kind of stuff, where at some point in the process there could be multiple separate paths, and the state at that point decides the path to be taken.

R Decision Making Statements

R programming language provides four decision making statements. They are :

  • R if statement – A boolean expression is evaluated and if TRUE, a block of statements are executed else, the execution flow continues with the execution of statements after if statement.
  • R if…else statement – A boolean expression is evaluated and if TRUE, a block of statements are executed else another block of statements are executed, then the execution flow continues with the execution of statements after if statement.
  • R if…else if…else statement – A boolean expression is evaluated and if TRUE, a block of statements are executed else the next if else block is executed and the process continues till the end of if…else if…else .. statement.
  • R switch statement – An expression is evaluated and based on the result, a value is selected from a list of values.

Conclusion :

In this R tutorial, we have learnt about R decision making statements – if, if…else, if…else if…else, switch.