if and if-else Statements in R
Control statements are expressions used to control the execution and flow of the program based on the conditions provided in the statements.These statements are used to make a decision after assessing the variable. if condition This control structure checks the expression provided in parenthesis is true or not. If true, the execution of the statements in braces {} continues. Syntax: if(expression) { statements .... .... } Example: x <- 100 if(x > 10){ print(paste(x, "is greater than 10")) } output [1] "100 is greater than 10" if-else condition It is similar to if condition but when the test expression in if condition fails, then statements in else condition are executed. Syntax: if(expression) ...