How it works…

In the preceding code, first it calculates the remainder within the if statement and compares the result with a zero. If the output of this conditional statement returns TRUE, then the code will print This is an even number; otherwise it will print This is an odd number. So, whenever you run the preceding code, the output will be as follows:

    > a <- 9
> if(a %% 2==0){
+ print("This is an even number")
+ } else {
+ print("This is an odd number")
+ }
[1] "This is an odd number"
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset