• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
in R Language by
Q:
IF, ELSE, ELSE IF Statement in R

1 Answer

0 votes
by

The if else statement

An if-else statement is a great tool for the developer trying to return an output based on a condition. In R, the syntax is:

if (condition) {
    Expr1 
} else {
    Expr2
}

The else if statement

We can further customize the control level with the else if statement. With elif, you can add as many conditions as we want. The syntax is:

if (condition1) { 
    expr1
    } else if (condition2) {
    expr2
    } else if  (condition3) {
    expr3
    } else {
    expr4
}

Related questions

0 votes
asked Nov 6, 2019 in R Language by MBarbieri
0 votes
asked Nov 4, 2019 in R Language by MBarbieri
...