找回密码
 注册
查看: 2803|回复: 0

R语言:Logic()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-17 10:03:41 | 显示全部楼层 |阅读模式
Logic(base)
Logic()所属R语言包:base

                                        Logical Operators
                                         逻辑运算符

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

These operators act on logical and number-like vectors.
这些经营者的行为逻辑和数字向量。


用法----------Usage----------


! x
x & y
x && y
x | y
x || y
xor(x, y)

isTRUE(x)



参数----------Arguments----------

参数:x, y
logical or "number-like" vectors (i.e., of type double (class numeric), integer, complex or raw), or objects for which methods have been written.
逻辑或数字般的“向量(即类型double(类numeric)integer,complex或raw),或对象哪些方法已被写入。


Details

详情----------Details----------

! indicates logical negation (NOT).
!表示逻辑否定(NOT)。

& and && indicate logical AND and | and || indicate logical OR.  The shorter form performs elementwise comparisons in much the same way as arithmetic operators.  The longer form evaluates left to right examining only the first element of each vector.  Evaluation proceeds only until the result is determined.  The longer form is appropriate for programming control-flow and typically preferred in if clauses.
&和&&表示逻辑“与”和|和||表示逻辑。较短的形式执行的elementwise比较多的算术运算符相同的方式。较长的形式评估左右只研究每个向量的第一个元素。直到结果确定评估的收益。较长的形式是适当的编程控制流,通常在if条款首选。

xor indicates elementwise exclusive OR.
xor表示的elementwise独家。

isTRUE(x) is an abbreviation of identical(TRUE, x), and so is true if and only if x is a length-one logical vector whose only element is TRUE and which has no attributes (not even names).
isTRUE(x)是identical(TRUE, x)的缩写,所以是真正的当且仅当x是TRUE长度一个逻辑向量,其元素是“没有属性(甚至没有名称)。

Numeric and complex vectors will be coerced to logical values, with zero being false and all non-zero values being true.  Raw vectors are handled without any coercion for !, &, | and xor, with these operators being applied bitwise (so ! is the 1s-complement).
数字和复杂的向量将被强制为逻辑值,零虚假和真实的所有非零值。原始向量处理,没有任何强制!,&,|和xor,与这些运营商的应用位元(!1S补)。

The operators !, & and | are generic functions: methods can be written for them individually or via the Ops (or S4 Logic, see below) group generic function.  (See Ops for how dispatch is computed.)
运营商!,&和|是通用的功能:方法可以为他们单独或通过Ops(或S4Logic,见下文)的书面组通用功能。 (见Ops如何计算调度。)

NA is a valid logical object.  Where a component of x or y is NA, the result will be NA if the outcome is ambiguous.  In other words NA & TRUE evaluates to NA, but NA & FALSE evaluates to FALSE.  See the examples below.
NA是一个有效的逻辑对象。凡组件x或y是NA,结果将是NA如果结果是模棱两可的。换句话说NA & TRUE值NA,但NA & FALSE值FALSE。见下面的例子。

See Syntax for the precedence of these operators: unlike many other languages (including S) the AND and OR operators do not have the same precedence (the AND operators are higher than the OR operators).
看到这些运算符的优先级的语法:AND和OR运算,不像许多其他语言(包括S)不具有相同的优先级(和运营商都高于OR运算符)。


值----------Value----------

For !, a logical or raw vector of the same length as x: names, dims and dimnames are copied from x.
!,为x长度相同的逻辑或原始向量:名称,变暗和dimnamesx复制。

For |, & and xor a logical or raw vector. The elements of shorter vectors are recycled as necessary (with a warning when they are recycled only fractionally). The rules for determining the attributes of the result are rather complicated.  Most attributes are taken from the longer argument, the first if they are of the same length.  Names will be copied from the first if it is the same length as the answer, otherwise from the second if that is.  For time series, these operations are allowed only if the series are compatible, when the class and tsp attribute of whichever is a time series (the same, if both are) are used.  For arrays (and an array result) the dimensions and dimnames are taken from first argument if it is an array, otherwise the second.
|,&和xor逻辑或原始向量。短向量的元素是必要的当他们回收仅小幅warning回收。确定结果的属性的规则相当复杂。从较长的论点,第一,如果他们是相同的长度,大多数属性。名称将被复制从第一,如果答案是相同的长度,从第二否则如果是这样。对于时间序列,这些操作允许只有当系列是兼容的,上课的时候tsp为准属性是一个时间序列(同样,如果两者都)正在使用。为阵列(数组结果)的尺寸和dimnames取自第一个参数,如果它是一个数组,否则第二。

For ||, && and isTRUE, a length-one logical vector.
||,&&和isTRUE,长度一个逻辑向量。


S4方法----------S4 methods----------

!, & and | are S4 generics, the latter two part of the Logic group generic (and hence methods need argument names e1, e2).
!,&和|S4仿制药,后两个Logic组通用的一部分(因此方法需要参数名e1, e2)。


参考文献----------References----------

The New S Language. Wadsworth & Brooks/Cole.

参见----------See Also----------

TRUE or logical.
TRUE或logical。

any and all for OR and AND on many scalar arguments.
any和allOR和AND许多标量参数。

Syntax for operator precedence.
Syntax运算符优先级。


举例----------Examples----------


y <- 1 + (x <- stats::rpois(50, lambda=1.5) / 4 - 1)
x[(x &gt; 0) &amp; (x &lt; 1)]    # all x values between 0 and 1[0和1之间的所有x值]
if (any(x == 0) || any(y == 0)) "zero encountered"

## construct truth tables :[#构造真值表:]

x <- c(NA, FALSE, TRUE)
names(x) <- as.character(x)
outer(x, x, "&amp;")## AND table[#和台式]
outer(x, x, "|")## OR  table[#或台式]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 03:11 , Processed in 0.026570 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表