Skip to Content
Modern R Programming Cookbook
book

Modern R Programming Cookbook

by Jaynal Abedin
October 2017
Beginner to intermediate
236 pages
7h 38m
English
Packt Publishing
Content preview from Modern R Programming Cookbook

There’s more…

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Cookbook, 2nd Edition

R Cookbook, 2nd Edition

JD Long, Paul Teetor

Publisher Resources

ISBN: 9781787129054Supplemental Content