R Data Analytics Practical Learning notes (2)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.