October 2017
Beginner to intermediate
236 pages
7h 38m
English
This is a very simple implementation of the conditional statement where the if statement part takes a scalar-valued input and produces a scalar-valued output with either TRUE or FALSE. Once the conditional statement returns its value, it executes the body of the code.
The most important thing to notice in this if …else code block is the use of curly braces. If you misplaced the curly braces just before the else keyword, then it will produce an error as follows:
if(a %% 2==0){ print("This is an even number") } else { print("This is an odd number") }
The corresponding console output is given as follows:
> a <- 9 > if(a %% 2==0){ + print("This is an even number") + } > else { Error: unexpected 'else' in "else" > print("This ...