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

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

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

                                        Determine Duplicate Elements
                                         确定重复的元素

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

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

duplicated() determines which elements of a vector or data frame are duplicates of elements with smaller subscripts, and returns a logical vector indicating which elements (rows) are duplicates.
duplicated()确定一个向量或数据框的元素下标较小的元素的副本,并返回一个逻辑是重复的元素(行)向量。

anyDuplicated(.) is a “generalized” more efficient shortcut for any(duplicated(.)).
anyDuplicated(.)是一个“广义”any(duplicated(.))更有效快捷。


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


duplicated(x, incomparables = FALSE, ...)

## Default S3 method:[默认方法]
duplicated(x, incomparables = FALSE,
           fromLast = FALSE, ...)

## S3 method for class 'array'
duplicated(x, incomparables = FALSE, MARGIN = 1,
           fromLast = FALSE, ...)

anyDuplicated(x, incomparables = FALSE, ...)
## Default S3 method:[默认方法]
anyDuplicated(x, incomparables = FALSE,
           fromLast = FALSE, ...)
## S3 method for class 'array'
anyDuplicated(x, incomparables = FALSE,
           MARGIN = 1, fromLast = FALSE, ...)



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

参数:x
a vector or a data frame or an array or NULL.
向量或一个数据框或一个数组或NULL。


参数:incomparables
a vector of values that cannot be compared. FALSE is a special value, meaning that all values can be compared, and may be the only value accepted for methods other than the default.  It will be coerced internally to the same type as x.
不能相比的值向量。 FALSE是一个特殊的值,这意味着可以比较所有值,可能是唯一的值比默认的其他方法接受。它将被裹挟国内相同类型的x。


参数:fromLast
logical indicating if duplication should be considered from the reverse side, i.e., the last (or rightmost) of identical elements would correspond to duplicated=FALSE.
逻辑表明,如果不应重复,即从反面考虑,最后(或最右边)相同的元素会对应到duplicated=FALSE。


参数:...
arguments for particular methods.
参数为特定的方法。


参数:MARGIN
the array margin to be held fixed: see apply, and note that MARGIN = 0 maybe useful.
举行的固定阵列保证金:apply,并注意MARGIN = 0也许有用。


Details

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

These are generic functions with methods for vectors (including lists), data frames and arrays (including matrices).
这些向量(包括名单),数据框和阵列(包括矩阵)方法的通用功能。

For the default methods, and whenever there are equivalent method definitions for duplicated and anyDuplicated, anyDuplicated(x,...) is a “generalized” shortcut for any(duplicated(x,...)), in the sense that it returns the index i of the first duplicated entry x[i] if there is one, and 0 otherwise.  Their behaviours may be different when at least one of duplicated and anyDuplicated has a relevant method.
对于默认的方法,每当有duplicated和anyDuplicated,anyDuplicated(x,...)是一个“广义”any(duplicated(x,...))快捷方式,在某种意义上说,它返回的等效方法定义指数i第一项重复x[i]如果有之一,0否则。他们的行为可能会有所不同,当至少一个duplicated和anyDuplicated有一个相关的方法。

duplicated(x, fromLast=TRUE) is equivalent to but faster than rev(duplicated(rev(x))).
duplicated(x, fromLast=TRUE)相当于,但比rev(duplicated(rev(x)))快。

The data frame method works by pasting together a character representation of the rows separated by \r, so may be imperfect if the data frame has characters with embedded carriage returns or columns which do not reliably map to characters.
粘贴一起\r,所以可能是不完善的,如果数据框嵌入回车或列不可靠映射到字符的字符分隔行的字符,表示数据框的方法工作。

The array method calculates for each element of the sub-array specified by MARGIN if the remaining dimensions are identical to those for an earlier (or later, when fromLast=TRUE) element (in row-major order).  This would most commonly be used to find duplicated rows (the default) or columns (with MARGIN = 2). Note that MARGIN = 0 returns an array of the same dimensionality attributes as x.
阵列的方法计算每个子阵列指定元素MARGIN如果剩下的尺寸是相同的那些较早(或更高版本,当fromLast=TRUE)元素(行大订单)。这将最常用的用来寻找重复的行(默认)或列(用MARGIN = 2)。注意MARGIN = 0返回一个数组相同的维属性x。

Missing values are regarded as equal, but NaN is not equal to NA_real_.
遗漏值被视为相等,但NaN不等于NA_real_。

Values in incomparables will never be marked as duplicated. This is intended to be used for a fairly small set of values and will not be efficient for a very large set.
价值观incomparables将永远不会被标记为重复。这是为了用于为一套相当小的值,并不会是一个非常大的一套有效的。

When used on a data frame with more than one column, or an array or matrix when comparing dimensions of length greater than one, this tests for identity of character representations.  This will catch people who unwisely rely on exact equality of floating-point numbers!
当一个数据框时,用多个列,或者一个数组或矩阵比较不止一个更大尺寸的长度,字符表示的身份为这个测试。这将赶上人不明智依靠精确的浮点数平等的人!

Character strings will be compared as byte sequences if any input is marked as "bytes".
字符串将作为字节序列进行比较,如果任何输入"bytes"标记。


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

duplicated(): For a vector input, a logical vector of the same length as x.  For a data frame, a logical vector with one element for each row.  For a matrix or array, and when MARGIN = 0, a logical array with the same dimensions and dimnames.
duplicated():对于一个向量输入,一个相同的长度为x的逻辑向量。逻辑向量为一个数据框,每一行的元素之一。对于一个矩阵或数组,当MARGIN = 0,具有相同的尺寸和dimnames逻辑阵列。

anyDuplicated(): a non-negative integer (of length one).
anyDuplicated():一个非负整数(长度为一)。


警告----------Warning----------

Using this for lists is potentially slow, especially if the elements are not atomic vectors (see vector) or differ only in their attributes.  In the worst case it is O(n^2).
使用名单这可能是缓慢的,尤其是如果元素不是原子的向量(见vector),或只在它们的属性不同。在最坏的情况下,它是O(n^2)。


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

The New S Language. Wadsworth & Brooks/Cole.

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

unique.
unique。


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


x <- c(9:20, 1:5, 3:7, 0:8)
## extract unique elements[#提取独特的元素。]
(xu <- x[!duplicated(x)])
## similar, same elements but different order:[#类似,相同的元素,但不同的顺序为:]
(xu2 <- x[!duplicated(x, fromLast = TRUE)])

## xu == unique(x) but unique(x) is more efficient[#徐==独特的(X),但唯一的(X)是更有效]
stopifnot(identical(xu,  unique(x)),
          identical(xu2, unique(x, fromLast = TRUE)))

duplicated(iris)[140:143]

duplicated(iris3, MARGIN = c(1, 3))
anyDuplicated(iris) ## 143[#143]

anyDuplicated(x)
anyDuplicated(x, fromLast = TRUE)

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-2 16:51 , Processed in 0.020361 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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