The use of a conditional statement or conditional operator is an essential part of any programming task. You may need to test a scenario in which there are two alternative options. Further work will depend on the outcome of the test scenario. In R, using the if statement, you can compare scenarios that usually have two alternative options. In this recipe, you will use the conditional statement if.
The use of the if conditional statement
Getting ready
The general structure of the if statement in R is as follows:
if(test_scenario){
valid_R_statements
...
}
From the general structure of the if statement, it is intuitive that if the test scenario produces TRUE, then the statement with curly braces will be executed...