© Margot Tollefson 2019
Margot TollefsonR Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-4405-0_13

13. Examples of Flow Control

Margot Tollefson1 
(1)
Stratford, IA, USA
 

This chapter gives some examples of flow control as well as ways to do the examples using indexing. The first example uses nested for loops and if/else statements. The second example uses the while statement. The third example is of nested for loops. The fourth example uses a for loop, an if statement, and a next statement. The fifth example is of a for loop, a repeat loop, an if statement, and a break statement.

Nested ‘for’ Loops with an ‘if/else’ Statement

In this example, we do an element-by-element substitution into a matrix based on an if/else test.

First, a two-by-five ...

Get R Quick Syntax Reference: A Pocket Guide to the Language, APIs and Library 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.