findInterval(base)
findInterval()所属R语言包:base
Find Interval Numbers or Indices
查找区间数或指数
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Find the indices of x in vec, where vec must be sorted (non-decreasingly); i.e., if i <- findInterval(x,v), we have v[i[j]] ≤ x[j] < v[i[j] + 1] where v[0] := - Inf, v[N+1] := + Inf, and N <- length(vec). At the two boundaries, the returned index may differ by 1, depending on the optional arguments rightmost.closed and all.inside.
xvec,其中vec必须排序(非少地)的指标,也就是说,如果i <- findInterval(x,v),我们有v[i[j]] ≤ x[j] < v[i[j] + 1]其中v[0] := - Inf,v[N+1] := + Inf,N <- length(vec)。在两个边界,返回的索引可能会有所不同1,根据可选参数rightmost.closed和all.inside。
用法----------Usage----------
findInterval(x, vec, rightmost.closed = FALSE, all.inside = FALSE)
参数----------Arguments----------
参数:x
numeric.
数字。
参数:vec
numeric, sorted (weakly) increasingly, of length N, say.
数字,排序(弱)越来越长N,,说。
参数:rightmost.closed
logical; if true, the rightmost interval, vec[N-1] .. vec[N] is treated as closed, see below.
逻辑,如果属实,最右边的时间间隔,vec[N-1] .. vec[N]封闭治疗,见下文。
参数:all.inside
logical; if true, the returned indices are coerced into 1,...,N-1, i.e., 0 is mapped to 1 and N to N-1.
逻辑;如果属实,返回指数被迫进入1,...,N-1,即0映射到1和N的N-1的。
Details
详情----------Details----------
The function findInterval finds the index of one vector x in another, vec, where the latter must be non-decreasing. Where this is trivial, equivalent to apply( outer(x, vec, ">="), 1, sum), as a matter of fact, the internal algorithm uses interval search ensuring O(n * log(N)) complexity where n <- length(x) (and N <- length(vec)). For (almost) sorted x, it will be even faster, basically O(n).
功能findInterval找到指数x另外,vec,而后者必须非递减的一个向量。这是微不足道的,相当于apply( outer(x, vec, ">="), 1, sum),事实上,内部算法使用间隔搜索确保O(n * log(N))复杂n <- length(x)(N <- length(vec))。 (几乎)排序x,它会更快,基本上O(n)。
This is the same computation as for the empirical distribution function, and indeed, findInterval(t, sort(X)) is identical to n * Fn(t; X[1],..,X[n]) where Fn is the empirical distribution function of X[1],..,X[n].
这是相同的经验分布函数的计算,事实上,findInterval(t, sort(X))是相同的n * Fn(t; X[1],..,X[n])其中FnX[1],..,X[n]的经验分布函数。
When rightmost.closed = TRUE, the result for x[j] = vec[N] ( = max(vec)), is N - 1 as for all other values in the last interval.
当rightmost.closed = TRUE结果x[j] = vec[N]( = max(vec))N - 1在过去的时间间隔的所有其他值。
值----------Value----------
vector of length length(x) with values in 0:N (and NA) where N <- length(vec), or values coerced to 1N-1) if and only if all.inside = TRUE (equivalently coercing all x values inside the intervals). Note that NAs are propagated from x, and Inf values are allowed in both x and vec.
向量的长度length(x)与0:N值(和NA),其中N <- length(vec),或强迫1N-1)值,当且仅当all.inside = TRUE(等效强迫的时间间隔内的所有x值)。注意NA的传播,从x,允许在两个Inf x值和vec。
作者(S)----------Author(s)----------
Martin Maechler
参见----------See Also----------
approx(*, method = "constant") which is a generalization of findInterval(), ecdf for computing the empirical distribution function which is (up to a factor of n) also basically the same as findInterval(.).
approx(*, method = "constant")findInterval(),ecdf这是(高达因素的n)也基本相同的作为findInterval的(经验分布函数的计算。)这是一个概括。
举例----------Examples----------
N <- 100
X <- sort(round(stats::rt(N, df=2), 2))
tt <- c(-100, seq(-2,2, len=201), +100)
it <- findInterval(tt, X)
tt[it < 1 | it >= N] # only first and last are outside range(X)[只有第一个和最后一个以外的范围(X)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|