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

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

[复制链接]
发表于 2012-2-16 20:48:48 | 显示全部楼层 |阅读模式
Arithmetic(base)
Arithmetic()所属R语言包:base

                                        Arithmetic Operators
                                         算术运算符

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

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

These binary operators perform arithmetic on numeric or complex vectors (or objects which can be coerced to them).
这些二元运算符执行算术数字或复杂的矢量(或可以强迫他们的对象)。


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


x + y
x - y
x * y
x / y
x ^ y
x %% y
x %/% y



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

参数:x, y
numeric or complex vectors or objects which can be coerced to such, or other objects for which methods have been written.
数字或复杂的向量或可强制该方法已被写入等,或其他对象的对象。


Details

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

The binary arithmetic operators are generic functions: methods can be written for them individually or via the Ops group generic function.  (See Ops for how dispatch is computed.)
二进制算术运算符是通用功能:方法可以写为他们单独或通过Ops组通用功能。 (见Ops如何计算调度。)

If applied to arrays the result will be an array if this is sensible (for example it will not if the recycling rule has been invoked).
如果应用到阵列的结果将是一个数组,如果这是明智的(例如,它不会,如果回收的规则已被调用)。

Logical vectors will be coerced to integer or numeric vectors, FALSE having value zero and TRUE having value one.
逻辑向量将被强制转换为整数或数字向量,FALSE零值和TRUE有一个值。

1 ^ y and y ^ 0 are 1, always. x ^ y should also give the proper limit result when either argument is infinite (i.e., +- Inf).
1 ^ y和y ^ 0是1,总是。 x ^ y也应给予适当的限制的结果,当任一参数是无限的(即+- Inf)。

Objects such as arrays or time-series can be operated on this way provided they are conformable.
这种方式提供,它们是相适应的,如数组或时间序列中的对象可以操作。

For real arguments, %% can be subject to catastrophic loss of accuracy if x is much larger than y, and a warning is given if this is detected.
对于真正的论据,%%可能受到灾难性损失的准确性,如果x比y较大,给予警告,如果这是检测。

%% and x %/% y can be used for non-integer y, e.g. 1 %/% 0.2, but the results are subject to representation error and so may be platform-dependent.  Because the IEC 60059 representation of 0.2 is a binary fraction slightly larger than 0.2, the answer to 1 %/% 0.2 should be 4 but most platforms give 5.
%%和x %/% y可用于非整数y,如1 %/% 0.2,但结果都表示错误等都可能是依赖于平台的。因为IEC 60059表示0.2是一个二进制数,稍微比0.2较大,答案应该1 %/% 0.24但大多数平台上给5。“

Users are sometimes surprised by the value returned, for example why (-8)^(1/3) is NaN.  For double inputs, R makes use of IEC 60559 arithmetic on all platforms, together with the C system function pow for the ^ operator.  The relevant standards define the result in many corner cases.  In particular, the result in the example above is mandated by the C99 standard.  On many Unix-alike systems the command man pow gives details of the values in a large number of corner cases.
用户有时惊讶返回值,例如为什么(-8)^(1/3)是NaN。双输入,研究使用IEC 60559在所有平台上的算术,连同C系统功能pow^运营商。有关标准的定义在许多角落情况的结果。在上面的例子中的结果,特别是C99标准规定。在许多Unix相似的系统命令man pow值给一个角落的情况下大量细节。

Arithmetic on type double in R is supposed to be done in "round to nearest, ties to even" mode, but this does depend on the compiler and FPU being set up correctly.
在R型双算术应该是圆最近,领带甚至模式做,但是这并不取决于编译器和FPU的设置是否正确。


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

These operators return vectors containing the result of the element by element operations.  The elements of shorter vectors are recycled as necessary (with a warning when they are recycled only fractionally).  The operators are + for addition, - for subtraction, * for multiplication, / for division and ^ for exponentiation.
这些运算符返回的元素操作元素的向量。短向量的元素是必要的当他们回收仅小幅warning回收。运营商+此外,-减法*乘法/分工和^幂。

%% indicates x mod y and %/% indicates integer division.  It is guaranteed that x == (x %% y) + y * (   x %/% y ) (up to rounding error) unless y == 0 where the result for %% is NA_integer_ or NaN (depending on the typeof of the arguments).
%%表示x mod y和%/%表示整数除法。这是保证x == (x %% y) + y * (   x %/% y )(舍入误差),除非y == 0其中的结果%%是NA_integer_或NaN(typeof的视参数)。

If either argument is complex the result will be complex, otherwise if one or both arguments are numeric, the result will be numeric.  If both arguments are of type integer, the type of the result of / and ^ is numeric and for the other operators it is integer (with overflow, which occurs at +/- (2^31 - 1), returned as NA_integer_ with a warning).
如果任一参数是复杂的,其结果将是复杂的,否则,如果一个或两个参数都是数字,其结果将是数字。如果两个参数都是整数类型,结果类型/和^是数字和其他运营商,它是整数(溢出,发生在+/- (2^31 - 1)返回NA_integer_警告)。

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.
确定结果的属性的规则相当复杂。从较长的论点,第一,如果他们是相同的长度,大多数属性。名称将被复制从第一,如果答案是相同的长度,从第二否则如果是这样。对于时间序列,这些操作允许只有当系列是兼容的,上课的时候tsp为准属性是一个时间序列(同样,如果两者都)正在使用。为阵列(数组结果)的尺寸和dimnames取自第一个参数,如果它是一个数组,否则第二。


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

These operators are members of the S4 Arith group generic, and so methods can be written for them individually as well as for the group generic (or the Ops group generic), with arguments c(e1, e2).
这些经营者的S4Arith组通用的成员,这样的方法可以为他们的书面单独组通用(或Ops组通用)以及参数,c(e1, e2) 。


注意----------Note----------

** is translated in the parser to ^, but this was undocumented for many years.  It appears as an index entry in Becker et al (1988), pointing to the help for Deprecated but is not actually mentioned on that page.  Even though it had been deprecated in S for 20 years, it was still accepted in R in 2008.
**翻译^分析器,但这是多年无证。它出现在Becker等人(1988)作为索引条目指向Deprecated,但实际上并不在该网页中提到的帮助。即使它已被废弃了20年的S,它仍然接受在2008年研发。


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

The New S Language. Wadsworth & Brooks/Cole.
about Floating-Point Arithmetic  ACM Computing Surveys, 23(1).<br> Postscript version available at http://www.validlab.com/goldberg/paper.ps Extended PDF version at http://www.validlab.com/goldberg/paper.pdf

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

sqrt for miscellaneous and Special for special mathematical functions.
sqrt杂和Special特殊的数学函数。

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

%*% for matrix multiplication.
%*%矩阵乘法。


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


x <- -1:12
x + 1
2 * x + 3
x %% 2 #-- is periodic[ - 是周期性]
x %/% 5

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-24 05:29 , Processed in 0.023592 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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