match(base)
match()所属R语言包:base
Value Matching
值匹配
译者:生物统计家园网 机器人LoveR
描述----------Description----------
match returns a vector of the positions of (first) matches of its first argument in its second.
match返回一个向量(第一)的第一个参数在其第二次比赛的位置。
%in% is a more intuitive interface as a binary operator, which returns a logical vector indicating if there is a match or not for its left operand.
%in%是作为一个二元操作符,它返回一个逻辑向量表示,如果有其左操作数不匹配或更直观的界面。
用法----------Usage----------
match(x, table, nomatch = NA_integer_, incomparables = NULL)
x %in% table
参数----------Arguments----------
参数:x
vector or NULL: the values to be matched.
向量或NULL:要匹配的值。
参数:table
vector or NULL: the values to be matched against.
向量或NULL:要匹配的值。
参数:nomatch
the value to be returned in the case when no match is found. Note that it is coerced to integer.
在没有找到匹配的情况时,要返回的值。请注意这是强迫integer。
参数:incomparables
a vector of values that cannot be matched. Any value in x matching a value in this vector is assigned the nomatch value. For historical reasons, FALSE is equivalent to NULL.
不能匹配值的向量。 x在此向量的值匹配的任何值分配nomatch值。由于历史的原因,FALSE相当于NULL的。
Details
详情----------Details----------
%in% is currently defined as <br> "%in%" <- function(x, table) match(x, table, nomatch = 0) > 0
%in%目前定义为参考"%in%" <- function(x, table) match(x, table, nomatch = 0) > 0
Factors, raw vectors and lists are converted to character vectors, and then x and table are coerced to a common type (the later of the two types in R's ordering, logical < integer < numeric < complex < character) before matching. If incomparables has positive length it is coerced to the common type.
因素的影响,原料向量和列表转换为特征向量,然后x和table被强制到一个共同的类型(两类R的顺序,逻辑<整数<数字< ;复杂的<字符)匹配。如果incomparables具有积极的长度,它裹挟常见的类型。
Matching for lists is potentially very slow and best avoided except in simple cases.
列出匹配的是潜在的非常缓慢,除了在简单的情况下,最好避免。
Exactly what matches what is to some extent a matter of definition. For all types, NA matches NA and no other value. For real and complex values, NaN values are regarded as matching any other NaN value, but not matching NA.
正是匹配在一定程度上是一个定义的问题。对于所有类型的NA匹配NA“没有其他的价值。真实而复杂的值,视为匹配任何其他NaN值NaN值,但不匹配NA。
That %in% never returns NA makes it particularly useful in if conditions.
%in%永远不会返回NAif条件,特别是在有用。
Character strings will be compared as byte sequences if any input is marked as "bytes".
字符串将作为字节序列进行比较,如果任何输入"bytes"标记。
值----------Value----------
A vector of the same length as x.
为x相同长度的向量。
match: An integer vector giving the position in table of the first match if there is a match, otherwise nomatch.
match:一个整数向量给table的第一场比赛,如果有一个匹配,否则nomatch的位置。
If x[i] is found to equal table[j] then the value returned in the i-th position of the return value is j, for the smallest possible j. If no match is found, the value is nomatch.
x[i]如果被发现等于table[j]然后在i个位置的返回值返回的值是最小的可能j j,。如果没有找到匹配的值是nomatch。
%in%: A logical vector, indicating if a match was located for each element of x: thus the values are TRUE or FALSE and never NA.
%in%:因此,一个逻辑向量,表示如果比赛是位于每个x元素的值是TRUE或FALSE“从来没有NA。
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole.
参见----------See Also----------
pmatch and charmatch for (partial) string matching, match.arg, etc for function argument matching. findInterval similarly returns a vector of positions, but finds numbers within intervals, rather than exact matches.
pmatch和charmatch字符串匹配(部分),match.arg,函数的参数匹配等。 findInterval同样返回一个职位的向量,但发现在时间间隔,而不是完全匹配的数字。
is.element for an S-compatible equivalent of %in%.
is.element%in%相当于S兼容。
举例----------Examples----------
## The intersection of two sets can be defined via match():[#可以通过比赛()定义两个集合的交集:]
## Simple version:[#简单的版本:]
## intersect <- function(x, y) y[match(x, y, nomatch = 0)][#相交< - 函数(X,Y)Y [比赛(X,Y,nomatch = 0)]]
intersect # the R function in base, slightly more careful[在基地的R函数,稍微多加小心]
intersect(1:10, 7:20)
1:10 %in% c(1,3,5,9)
sstr <- c("c","ab","B","bba","c",NA,"@","bla","a","Ba","%")
sstr[sstr %in% c(letters, LETTERS)]
"%w/o%" <- function(x, y) x[!x %in% y] #-- x without y[ - X无Y]
(1:10) %w/o% c(3,7,12)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|