Conditional Statements in R

In programming, we often want to check a conditional statement and then do something if the condition is met and do something else if the condition is not met. This is done using the If conditions.

There are two general forms of decision making structures found in most of the programming languages:

if statement

if(BooleanExpression)
    statement;
if(BooleanExpression) {
    statement1;
    statement2;
    ...
}

If the BoolenExpression is true, then the statements will be executed.

if...else statement

    statement or block 1
else
    statement or block 2

Examples

This content is for paid members only.

Join our membership for lifelong unlimited access to all our data science learning content and resources.