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

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

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

                                        Relational Operators
                                         关系运算符

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

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

Binary operators which allow the comparison of values in atomic vectors.
二元运算符,使原子向量中的值比较。


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


x < y
x > y
x <= y
x >= y
x == y
x != y



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

参数:x, y
atomic vectors, symbols, calls, or other objects for which methods have been written.
原子的向量,符号,电话,或其他对象,该方法已被写入。


Details

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

The binary comparison 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如何计算调度。)

Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use: see locales.  The collating sequence of locales such as en_US is normally different from C (which should use ASCII) and can be surprising.  Beware of making any assumptions about the collation order: e.g. in Estonian Z comes between S and T, and collation is not necessarily character-by-character – in Danish aa sorts as a single letter, after z.  In Welsh ng may or may not be a single sorting unit: if it is it follows g.  Some platforms may not respect the locale and always sort in numerical order of the bytes in an 8-bit locale, or in Unicode point order for a UTF-8 locale (and may not sort in the same order for the same language in different character sets).  Collation of non-letters (spaces, punctuation signs, hyphens, fractions and so on) is even more problematic.
字符串比较特征向量是字典内使用字符串中使用的语言环境的整理顺序:看到locales。如en_US语言环境的整理顺序通常是不同的C(应该使用ASCII),可奇怪的。谨防排序顺序作出任何假设例如:在爱沙尼亚的ZS和T,整理不一定是字符的字符 - 在丹麦aa作为一个单一的字母排序之间,后<X >在威尔士的z可能或可能不会是一个单一的排序单元:如果它是如下ng。有些平台可能不尊重数字顺序字节的区域和总排序,在一个8位的区域,或在一个UTF-8语言环境中的Unicode点顺序(并可能无法在相同的语言相同的顺序进行排序,在不同的字符套)。非字母(空格,标点符号的迹象,连字符,分数和等)的整理更是问题。

Character strings can be compared  with different marked encodings (see Encoding): they are translated to UTF-8 before comparison.
字符串可以相比具有显着的不同编码(见Encoding):他们被翻译为UTF-8前比较。

At least one of x and y must be an atomic vector, but if the other is a list R attempts to coerce it to the type of the atomic vector: this will succeed if the list is made up of elements of length one that can be coerced to the correct type.
至少有一个x和y必须是一个原子的向量,但如果另一种是的名单&#341;试图强迫它的原子向量类型:这会成功,如果列表由长度为1的元素可以强制转换为正确的类型。

If the two arguments are atomic vectors of different types, one is coerced to the type of the other, the (decreasing) order of precedence being character, complex, numeric, integer, logical and raw.
如果这两个参数是不同类型的原子向量,一种是被迫到其它类型的,优先的性格,复杂,数字,整数,逻辑和原材料(递减)的顺序。

Missing values (NA) and NaN values are regarded as non-comparable even to themselves, so comparisons involving them will always result in NA.  Missing values can also result when character strings are compared and one is not valid in the current collation locale.
遗漏值(NA)NaN值视为非相媲美,甚至对自己,所以它们涉及的比较总是会导致在NA。遗漏值也可能导致字符串比较时,没有一个是在目前的排序规则语言环境的有效。

Language objects such as symbols and calls are deparsed to character strings before comparison.
语言对象,如符号,并呼吁deparsed字符串比较之前。


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

A logical vector indicating the result of the element by element comparison.  The elements of shorter vectors are recycled as necessary.
逻辑向量表示元素的元素比较的结果。短向量的元素是必要的回收。

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


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

These operators are members of the S4 Compare 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).
这些经营者的S4Compare组通用的成员,这样的方法可以为他们的书面单独组通用(或Ops组通用)以及参数,c(e1, e2) 。


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

Do not use == and != for tests, such as in if expressions, where you must get a single TRUE or FALSE.  Unless you are absolutely sure that nothing unusual can happen, you should use the identical function instead.
不使用==和!=测试,如在if表达式,你必须得到一个单一的TRUE或FALSE。除非你绝对相信会发生什么不寻常的,你应该使用identical功能。

For numerical and complex values, remember == and != do not allow for the finite representation of fractions, nor for rounding error.  Using all.equal with identical is almost always preferable.  See the examples.
对于数字和复杂的价值观,记得==和!=不允许分数有限的代表性,也没有舍入误差。使用all.equal用identical几乎总是可取的。见的例子。


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

The New S Language. Wadsworth &amp; Brooks/Cole.
introduction see http://en.wikipedia.org/wiki/Collating_sequence.  The Unicode Collation Algorithm (http://unicode.org/reports/tr10/) is likely to be increasingly influential.  Where available R makes use of ICU (http://site.icu-project.org/ for collation.

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

factor for the behaviour with factor arguments.
factor因子参数的行为。

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

icuSetCollate to tune the string collation algorithm when ICU is in use.
icuSetCollate调整字符串排序算法,在使用时,加护病房。


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


x <- stats::rnorm(20)
x < 1
x[x > 0]

x1 <- 0.5 - 0.3
x2 <- 0.3 - 0.1
x1 == x2                           # FALSE on most machines[虚报大多数机器]
identical(all.equal(x1, x2), TRUE) # TRUE everywhere[TRUE,无处不在]


# range of most 8-bit charsets, as well as of Latin-1 in Unicode[大多数8位字符集范围,以及在Unicode Latin-1的]
z <- c(32:126, 160:255)
x <- if(l10n_info()$MBCS) {
    intToUtf8(z, multiple = TRUE)
} else rawToChar(as.raw(z), multiple= TRUE)
## by number[#数字]
writeLines(strwrap(paste(x, collapse=" "), width = 60))
## by locale collation[#语言环境整理]
writeLines(strwrap(paste(sort(x), collapse=" "), width = 60))

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


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

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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