3.17 Program Structure
There are 3 types of structures:
Sequential structure: A---B
Select structure: A program module that executes only if certain conditions are met.
Cyclic structure: As long as certain conditions are met, the program module will be continuously executed.
3.18 for Loop traversal
SEQ: sequence. The SEQ () function creates a sequence.
Note: When SEQ is a sequence, it is the name of each sequence, and when SEQ is a number, it is written for (I-1:n).
For a data frame, using a For loop by default is traversed by columns. How to traverse by rows. Use:
3.19 While loop condition is true
while (condition) expr
In general, the variable i in condition is assigned outside the while statement.
Next is a loop that jumps out of a certain time
Break is to terminate the loop and jump out of the dead loop
3.20 repeat
while (TRUE) is a dead loop
Using repeat, without condition, is itself a dead loop. To jump out with a break.
That is: while (TRUE) {} is equivalent to repeat {}
3.21 function Use (user-defined function)
function can have no return value
If you define a function that does not have a parameter, the parameter is entered when the function is called and an error is made. Conversely, a function with parameters is defined, and when the function is called, there is no input parameter and an error is also found.
When a function is defined, a default value is given to the parameter, and when the function is called, no parameter is entered, and the function executes the default parameter value. Such as:
The parameter position of the function can be swapped and replaced, with the name of the parameter. Function_name (parameter2=, parameter1=)
When there are not many parameters to know, use the ellipsis "..." to indicate.
3.22 vectorization calculation-generating vectors
Use a colon to decrement
Seq () decrements by parameter by= negative value
3.23 vectorization Calculation-vectorization operation
R Data Analytics Practical Learning notes (2)