Debian Codegraph @

man/seqXtend.Rd

raw
1 \name{seqXtend}
2 \alias{seqXtend}
3 \title{Sequence Covering the Range of X, including X}
4 \description{
5 Produce a sequence of unique values (sorted increasingly),
6 \emph{containing} the initial set of values \code{x}.
7 This can be useful for setting prediction e.g. ranges in nonparametric
8 regression.
9 }
10 \usage{
11 seqXtend(x, length., method = c("simple", "aim", "interpolate"),
12 from = NULL, to = NULL)
13 }
14 \arguments{
15 \item{x}{numeric vector.}
16 \item{length.}{integer specifying \emph{approximately} the desired
17 \code{\link{length}()} of the result.}
18 \item{method}{string specifying the method to be used. The default,
19 \code{"simple"} uses \code{\link{seq}(*, length.out = length.)} where
20 \code{"aim"} aims a bit better towards the desired final length,
21 and \code{"interpolate"} interpolates evenly \emph{inside}
22 each interval \eqn{[x_i, x_{i+1}]}{(x[i], x[i+1])} in a way to
23 make all the new intervalls of approximately the same length.}
24 \item{from, to}{numbers to be passed to (the default method for)
25 \code{\link{seq}()}, defaulting to the minimal and maximal \code{x}
26 value, respectively.}
27 }
28 \note{
29 \code{method = "interpolate"} typically gives the best results. Calling
30 \code{\link{roundfixS}}, it also need more computational resources
31 than the other methods.
32 }
33 \value{
34 numeric vector of increasing values, of approximate length
35 \code{length.}
36 (unless \code{length. < length(unique(x))} in which case, the result
37 is simply \code{sort(\link{unique}(x))}),
38 containing the original values of \code{x}.
39
40 From, \code{r <- seqXtend(x, *)}, the original values are at
41 indices \code{ix <- match(x,r)}, i.e., \code{identical(x, r[ix])}.
42 }
43 \author{Martin Maechler}
44 \seealso{\code{\link{seq}}; \code{\link{plotDS}} can make particularly
45 good use of \code{seqXtend()}
46 }
47 \examples{
48 a <- c(1,2,10,12)
49 seqXtend(a, 12)# --> simply 1:12
50 seqXtend(a, 12, "interp")# ditto
51 seqXtend(a, 12, "aim")# really worse
52 stopifnot(all.equal(seqXtend(a, 12, "interp"), 1:12))
53
54 ## for a "general" x, however, "aim" aims better than default
55 x <- c(1.2, 2.4, 4.6, 9.9)
56 length(print(seqXtend(x, 12))) # 14
57 length(print(seqXtend(x, 12, "aim"))) # 12
58 length(print(seqXtend(x, 12, "int"))) # 12
59
60 ## "interpolate" is really nice:
61 xt <- seqXtend(x, 100, "interp")
62 plot(xt, main="seqXtend(*, 100, \"interpol\")")
63 points(match(x,xt), x, col = 2, pch = 20)
64 # .... you don't even see that it's not equidistant
65 # whereas the cheap method shows ...
66 xt2 <- seqXtend(x, 100)
67 plot(xt2, col="blue")
68 points(match(x,xt2), x, col = 2, pch = 20)
69
70 ## with "Date" objects
71 Drng <- as.Date(c("2007-11-10", "2012-07-12"))
72 (px <- pretty(Drng, n = 16)) # say, for the main labels
73 ## say, a finer grid, for ticks -- should be almost equidistant
74 n3 <- 3*length(px)
75 summary(as.numeric(diff(seqXtend(px, n3)))) # wildly varying
76 summary(as.numeric(diff(seqXtend(px, n3, "aim")))) # (ditto)
77 summary(as.numeric(diff(seqXtend(px, n3, "int")))) # around 30
78 }
79 \keyword{manip}
80 \keyword{utilities}