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

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

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

                                        Test Objects for Exact Equality
                                         测试对象为精确平等

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

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

The safe and reliable way to test two objects for being exactly equal.  It returns TRUE in this case, FALSE in every other case.
安全可靠的方式来测试是完全相等的两个对象。返回TRUE在这种情况下,FALSE在所有其他情况。


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


identical(x, y, num.eq = TRUE, single.NA = TRUE, attrib.as.set = TRUE,
                ignore.bytecode = TRUE)



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

参数:x, y
any R objects.
任何R对象。


参数:num.eq
logical indicating if (double and complex non-NA) numbers should be compared using == ("equal"), or by bitwise comparison.  The latter (non-default) differentiates between -0 and +0.
逻辑表示,如果(double和complex非NA)数字应比使用==(“等于”),或按位比较。后者(非默认)-0和+0之间的区别。


参数:single.NA
logical indicating if there is conceptually just one numeric NA and one NaN;  single.NA = FALSE differentiates bit patterns.
逻辑表示,如果有是概念只是一个数字NA和一个NaN;single.NA = FALSE不同的位模式。


参数:attrib.as.set
logical indicating if attributes of x and y should be treated as unordered tagged pairlists (“sets”); this currently also applies to slots of S4 objects.  It may well be too strict to set attrib.as.set = FALSE.
逻辑表明,如果attributesx和y应视为无序标签pairlists(“套”),这也适用于slot的S4的对象。它很可能是过于严格设置attrib.as.set = FALSE。


参数:ignore.bytecode
logical indicating if byte code should be ignored when comparing functions.
逻辑表明,如果比较功能时,应该被忽略的字节码。


Details

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

A call to identical is the way to test exact equality in if and while statements, as well as in logical expressions that use && or ||.  In all these applications you need to be assured of getting a single logical value.
一个identical调用的方式来测试在if和while报表,以及在逻辑表达式中使用&&或||确切平等。在所有这些应用程序,你需要保证得到一个单一的逻辑值。

Users often use the comparison operators, such as == or !=, in these situations.  It looks natural, but it is not what these operators are designed to do in R.  They return an object like the arguments.  If you expected x and y to be of length 1, but it happened that one of them wasn't, you will not get a single FALSE.  Similarly, if one of the arguments is NA, the result is also NA.  In either case, the expression if(x == y).... won't work as expected.
如==或!=比较运算符,用户往往在这些情况下使用。它看起来很自然,但它并不是这些运营商都在R他们像参数返回一个对象。如果你期望x和y长度为1,但它发生了,其中之一是没有,你不会得到一个单一的FALSE。同样,如果一个参数是NA,结果也是NA。在这两种情况下,表达if(x == y)....不会如预期般运作。

The function all.equal is also sometimes used to test equality this way, but was intended for something different:  it allows for small differences in numeric results.
功能all.equal有时也用来测试平等这种方式,但目的是不同的东西:它允许在数值结果的微小差异。

The computations in identical are also reliable and usually fast.  There should never be an error.  The only known way to kill identical is by having an invalid pointer at the C level, generating a memory fault.  It will usually find inequality quickly. Checking equality for two large, complicated objects can take longer if the objects are identical or nearly so, but represent completely independent copies.  For most applications, however, the computational cost should be negligible.
identical计算也可靠,通常比较快。不应该是一个错误。杀identical已知的唯一方式是在C级有一个无效的指针,产生了内存故障。它通常会发现不平等迅速。检查两个大型的,复杂的对象平等需要更长的时间,如果对象是相同或接近,但表示完全独立的副本。然而,对于大多数应用,成本的计算应该是可以忽略不计。

If single.NA is true, as by default, identical sees NaN as different from NA_real_, but all NaNs are equal (and all NA of the same type are equal).
如果single.NA是真的,因为默认情况下,identical看到NaN从NA_real_不同,但所有的NaNS是相等的(和所有的NA 是同一类型的平等)。

Character strings are regarded as identical if they are in different marked encodings but would agree when translated to UTF-8.
如果他们是在显着不同的编码,但会同意转换为UTF-8时,字符串被视为相同。

If attrib.as.set is true, as by default, comparison of attributes view them as a set (and not a vector, so order is not tested).
attrib.as.set如果是真实的,因为默认情况下,属性比较视一套(而不是一个向量,所以为了不测试)。

If ignore.bytecode is true (the default), the compiled bytecode of a function (see cmpfun) will be ignored in the comparison. If it is false, functions will compare equal only if they are copies of the same compiled object (or both are uncompiled).  To check whether two different compiles are equal, you should compare the results of disassemble().
ignore.bytecode如果true(默认),功能(见cmpfun)编译的字节码将被忽略的比较。如果它是假的,功能比较平等的,只有当他们是相同的编译对象(或两者都是未编译)的副本。要检查是否两个不同的编译都是平等的,你应该比较结果disassemble()。

Note that identical(x,y,FALSE,FALSE,FALSE,FALSE) pickily tests for very exact equality.
请注意,identical(x,y,FALSE,FALSE,FALSE,FALSE)pickily测试非常精确的平等。


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

A single logical value, TRUE or FALSE, never NA and never anything other than a single value.
一个逻辑值,TRUE或FALSE,从来没有NA“从来没有任何一个单一的值以外。


作者(S)----------Author(s)----------


John Chambers and R Core



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

Programming with Data.  A Guide to the S Language. Springer.

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

all.equal for descriptions of how two objects differ; Comparison for operators that generate elementwise comparisons. isTRUE is a simple wrapper based on identical.
all.equal两个对象不同的描述;运营商产生的elementwise比较的比较。 isTRUE上identical基于一个简单的包装。


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


identical(1, NULL) ## FALSE -- don't try this with ==[#假 - 不要尝试这个==]
identical(1, 1.)   ## TRUE in R (both are stored as doubles)[#TRUE,在R(都存储双打)]
identical(1, as.integer(1)) ## FALSE, stored as different types[#假,为不同类型的存储]

x <- 1.0; y <- 0.99999999999
## how to test for object equality allowing for numeric fuzz :[#如何测试对象,让数字模糊平等:]
(E <- all.equal(x,y))
isTRUE(E) # which is simply defined to just use[这是简单的定义,只使用]
identical(TRUE, E)
## If all.equal thinks the objects are different, it returns a[#如果all.equal认为对象是不同的,它返回一个]
## character string, and the above expression evaluates to FALSE[#字符串,上面的表达式的计算结果为FALSE]

## even for unusual R objects :[#即使不寻常的R对象:]
identical(.GlobalEnv, environment())

### ------- Pickyness Flags : -----------------------------[#------- Pickyness标志的:-----------------------------]

## the infamous example:[#臭名昭著的例子:]
identical(0., -0.) # TRUE, i.e. not differentiated[为TRUE,即不区分]
identical(0., -0., num.eq = FALSE)
## similar:[#类似:]
identical(NaN, -NaN) # TRUE[真]
identical(NaN, -NaN, single.NA=FALSE) # differ on bit-level[不同的位级]
## for functions:[职能:]
f <- function(x) x
f
g <- compiler::cmpfun(f)
g
identical(f, g)
identical(f, g, ignore.bytecode=FALSE)


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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-22 21:44 , Processed in 0.020121 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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