Skip to content

Commit 5f9820c

Browse files
committed
Delete unneeded function; add help file for orderstats
1 parent 59067b4 commit 5f9820c

File tree

7 files changed

+88
-33
lines changed

7 files changed

+88
-33
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: spatstat.utils
2-
Version: 1.18-0
3-
Date: 2020-11-14
2+
Version: 1.19-0
3+
Date: 2020-12-19
44
Title: Utility Functions for 'spatstat'
55
Authors@R: c(person("Adrian", "Baddeley",
66
role = c("aut", "cre"),

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export("revcumsum")
153153
export("reverse.xypolygon")
154154
export("rhs.of.formula")
155155
export("rhs.of.formula<-")
156-
export("romansort")
157156
export("samefunction")
158157
export("sensiblevarname")
159158
export("short.deparse")

R/utiltext.R

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#'
44
#' Utilities for text output, etc
55
#'
6-
#' $Revision: 1.7 $ $Date: 2020/02/06 07:35:31 $
6+
#' $Revision: 1.8 $ $Date: 2020/12/19 08:45:05 $
77
#'
88

99
# text magic
@@ -469,30 +469,6 @@ fontify <- function(x, font="italic") {
469469
return(NULL)
470470
}
471471

472-
romansort <- local({
473-
474-
# sort character strings in order of Roman alphabet
475-
476-
romansort <- function(x) {
477-
if(!is.character(x)) return(sort(x))
478-
x <- as.vector(x)
479-
## convert each 'word' to a vector of single characters
480-
cc <- strsplit(x, "")
481-
## find position of each character in Roman alphabet
482-
mm <- lapply(cc, match, table=c(letters, LETTERS))
483-
mmax <- max(unlist(mm), na.rm=TRUE)
484-
## encode
485-
nn <- sapply(mm, powercode, base=mmax)
486-
## find ordering
487-
oo <- order(nn, na.last=TRUE)
488-
return(x[oo])
489-
}
490-
491-
powercode <- function(x, base) sum(x * base^rev((seq_len(length(x))-1)))
492-
493-
romansort
494-
})
495-
496472
variablesintext <- function(x) all.vars(as.expression(parse(text=x)))
497473

498474
## convert numeric matrix to character, and blank out lower sub-diagonal.

inst/doc/packagesizes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
1313
"2018-10-19" "1.12-0" 30 169 0 3303 1944
1414
"2018-10-31" "1.13-0" 30 169 0 3304 1944
1515
"2020-11-14" "1.18-0" 31 171 0 3354 1965
16+
"2020-12-19" "1.19-0" 32 170 0 3330 1965

man/orderstats.Rd

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
\name{orderstats}
2+
\alias{orderstats}
3+
\alias{orderwhich}
4+
\title{
5+
Compute Order Statistics
6+
}
7+
\description{
8+
Compute the \code{k}-th smallest value in a dataset,
9+
or find which entry in a dataset is the \code{k}-th smallest.
10+
}
11+
\usage{
12+
orderstats(x, k, decreasing = FALSE)
13+
orderwhich(x, k, decreasing = FALSE)
14+
}
15+
\arguments{
16+
\item{x}{
17+
Data whose order statistics will be computed. A numeric vector.
18+
}
19+
\item{k}{
20+
Rank. An integer, or vector of integers.
21+
}
22+
\item{decreasing}{
23+
Logical value specifing whether a rank of 1
24+
is assigned to the highest value (\code{decreasing=TRUE})
25+
or the lowest value (\code{decreasing=FALSE}, the default).
26+
}
27+
}
28+
\details{
29+
These are low-level functions for efficiently computing order statistics:
30+
\code{orderstats(x, k)} returns the \code{k}-th smallest value in \code{x},
31+
and \code{orderwhich(x, k)} returns the \emph{position} of the
32+
\code{k}-th smallest value in \code{x}.
33+
34+
Given a dataset of values \eqn{x_1, \dots, x_n}{x[1], ..., x[n]},
35+
the \emph{order statistic} of rank \eqn{k} is the \eqn{k}-th smallest
36+
value in the dataset. The order statistic of rank 1 is the smallest
37+
value, and the order statistic of rank \eqn{n} is the largest value.
38+
The order statistic of rank \eqn{k} is denoted \eqn{x_{[k]}}{x([k])}.
39+
40+
The full sequence of order statistics
41+
\deqn{
42+
x_{[1]} \le x_{[2]} \le \dots \le x_{[n]}
43+
}{
44+
x([1]) <= x([2]) <= ... <= x([n])
45+
}
46+
can simply be obtained by sorting the original values
47+
into increasing order.
48+
49+
The command \code{orderstats(x, k)} is equivalent to
50+
\code{\link{sort}(x)[k]}; it calculates the
51+
\code{k}-th smallest value in \code{x}.
52+
53+
The command \code{orderwhich(x, k)} is equivalent to
54+
\code{\link{order}(x)[k]}. It identifies the \emph{position} of the
55+
\code{k}-th smallest value in \code{x}, that is, it returns the
56+
index \code{j} such that \code{x[j]} is the \code{k}-th smallest value
57+
in \code{x}.
58+
59+
The functions \code{orderstats} and \code{orderwhich} are more
60+
efficient than using \code{sort} and \code{order}
61+
when it is only desired to calculate a few of the
62+
order statistics (for example, only the smallest and second-smallest
63+
values in the dataset).
64+
}
65+
\value{
66+
\code{orderstats} returns a vector of the same kind as \code{x},
67+
with the same length as \code{k}.
68+
\code{orderwhich} returns an integer vector
69+
with the same length as \code{k}.
70+
}
71+
\author{
72+
\adrian.
73+
}
74+
\seealso{
75+
\code{\link{sort}}, \code{\link{order}}.
76+
}
77+
\examples{
78+
x <- runif(10)
79+
orderstats(x, 2)
80+
sort(x)[2]
81+
orderwhich(x, 2:3)
82+
order(x)[2:3]
83+
}
84+
\keyword{math}

man/spatstat.utils-internal.Rd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@
6565
\alias{NNdist2segments}
6666
\alias{numalign}
6767
\alias{nzpaste}
68-
\alias{orderstats}
69-
\alias{orderwhich}
7068
\alias{\%orifnull\%} %DoNotExport
7169
%NAMESPACE export("%orifnull%")
7270
\alias{padtowidth}
@@ -172,8 +170,6 @@ niceround(x, m)
172170
NNdist2segments(xp, yp, x0, y0, x1, y1, bigvalue)
173171
numalign(i, nmax, zero)
174172
nzpaste(\dots, sep, collapse)
175-
orderstats(x, k, decreasing)
176-
orderwhich(x, k, decreasing)
177173
a \%orifnull\% b
178174
padtowidth(a, b, justify)
179175
passthrough(.Fun, \dots, .Fname)

tests/tekst.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ simplenumber(1/3, unit="km")
5656
simplenumber(2/3, unit="km")
5757
simplenumber(-2, unit="km")
5858

59-
romansort(c("Eb", "Au"))
6059
makeCutLabels(0:3)

0 commit comments

Comments
 (0)