October 2015
Beginner to intermediate
246 pages
4h 55m
English
Control structures in computer programming are statements that decide the execution (or not) of certain pieces of code. In while and if, they are based on a condition that evaluates to TRUE or FALSE, and in for, the statement is executed for every element of the input sequence.
In R, all the control structures have the same coding pattern, as follows:
control_structure(condition or sequence){code block}The following is a small example of an if...else block in R. You can play with it by changing the value of a:
> a <- 5 > if(a > 0){print("a is greater than 0")} else + { print("a is smaller than 0")} [1] "a is greater than 0"
The else clause must start in the same line where the if clause ends.
With an ...
Read now
Unlock full access