CHAPTER 4

image

Control Structures

In Chapter 3, you saw an example of a simple function for calculating a person’s body mass index (BMI). The function used logic to determine the person’s risk category. The use of logic, conditional statements, and loops are all inherent in controlling the flow of a program. Although there are many different ways to write conditional statements, and loops, too, for that matter, they all boil down to testing to see if some condition is true or false and then behaving accordingly. A program is nothing more or less than a series of instructions telling a computer what to do. As I have mentioned, R is both functional ...

Get Beginning R: An Introduction to Statistical Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.