(r language) statement groups, loops, and conditional actions

Source: Internet
Author: User

R is an expression language, meaning that its command type has only functions or expressions and returns a result from them.
The statement group is determined by the curly braces '{}', at which point the result is the result of the last statement in the group that can return a value.

conditional Statements

> if (expr_1) expr_2 else expr_3
Where the conditional expression EXPR1 must return a logical value, operator && and | | are often used in the condition section.
& | and &&, | | The difference is that,& and | are calculated in terms of element-wise,&& and | | The first element of the vector is evaluated, and the second parameter is evaluated only when required.
The vector version of the IF/ELSE structure is the function IfElse, which is in the form of IfElse (condition,a,b), and the rule that produces the function result is: If Condition[i] is true, the corresponding a[i] element The opposite is the b[i] element. According to this principle the function returns a vector consisting of the corresponding elements in a, B, the length of the vector and the longest parameter.

Looping Statements

> For (name in expr_1) expr_2
Where name is a loop variable, expr1 is a vector expression (usually a sequence of 1:20), and EXPR2 is often a group of expression statements, EXPR2 is repeated repeatedly as name takes the value of the expr1 result vector in turn.

> repeat(expr)

> while (condition) expr

The break statement can be used to interrupt any loop, possibly a non-normal interrupt. And this is the only way to stop the repeat loop.

The next statement can abort a specific loop and jump to the next one.

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.