10CONDITIONS AND LOOPS
To write more sophisticated programs with R, you’ll need to control the flow and order of execution in your code. One fundamental way to do this is to make the execution of certain sections of code dependent on a condition. Another basic control mechanism is the loop, which repeats a block of code a certain number of times. In this chapter, we’ll explore these core programming techniques using if-else statements, for and while loops, and other control structures.
10.1 if Statements
The if statement is the key to controlling exactly which operations are carried out in a given chunk of code. An if statement runs a block of ...
Get The Book of R now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.