R – Decision Making Statements

With R decision-making statements you can easily take decisions based on different conditions. The following are the decision-making statements in the R programming language:

  • if statement
  • if…else statement
  • if…elseif..else statement

if statement

The if decision-making statement executes the code if the condition is true. The following is the syntax:

Let us see an example to implement the if statement in the R programming language:

Output

if…else statement

The if…else decision-making statement executes some code if the condition is true and another code if the condition is false. The false condition comes under else.

The following is the syntax:

Let us see an example to implement the if…else statement in the R programming language:

Output

if…else if…else statement

The if…else if…else statement executes code for different conditions. If more than 2 conditions are true, you can use else for the false condition.

The following is the syntax:

Let us see an example to implement the if…else if…else statement in the R programming language:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


Read More:

R Loop Control Statements
R Strings
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading