| orderstats {spatstat.utils} | R Documentation |
Compute the k-th smallest value in a dataset,
or find which entry in a dataset is the k-th smallest.
orderstats(x, k, decreasing = FALSE) orderwhich(x, k, decreasing = FALSE)
x |
Data whose order statistics will be computed. A numeric vector. |
k |
Rank. An integer, or vector of integers. |
decreasing |
Logical value specifing whether a rank of 1
is assigned to the highest value ( |
These are low-level functions for efficiently computing order statistics:
orderstats(x, k) returns the k-th smallest value in x,
and orderwhich(x, k) returns the position of the
k-th smallest value in x.
Given a dataset of values x[1], ..., x[n], the order statistic of rank k is the k-th smallest value in the dataset. The order statistic of rank 1 is the smallest value, and the order statistic of rank n is the largest value. The order statistic of rank k is denoted x([k]).
The full sequence of order statistics
x([1]) <= x([2]) <= ... <= x([n])
can simply be obtained by sorting the original values into increasing order.
The command orderstats(x, k) is equivalent to
sort(x)[k]; it calculates the
k-th smallest value in x.
The command orderwhich(x, k) is equivalent to
order(x)[k]. It identifies the position of the
k-th smallest value in x, that is, it returns the
index j such that x[j] is the k-th smallest value
in x.
The functions orderstats and orderwhich are more
efficient than using sort and order
when it is only desired to calculate a few of the
order statistics (for example, only the smallest and second-smallest
values in the dataset).
orderstats returns a vector of the same kind as x,
with the same length as k.
orderwhich returns an integer vector
with the same length as k.
Adrian Baddeley Adrian.Baddeley@curtin.edu.au.
x <- runif(10) orderstats(x, 2) sort(x)[2] orderwhich(x, 2:3) order(x)[2:3]