File: resample.Rd

package info (click to toggle)
gdata 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 964 kB
  • sloc: sh: 27; makefile: 15
file content (40 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
\name{resample}
\alias{resample}
\title{Consistent Random Samples and Permutations}
\description{
  Take a sample of the specified size from the
  elements of \code{x} using either with or without replacement.
}
\usage{
resample(x, size, replace = FALSE, prob = NULL)
}
\arguments{
  \item{x}{A numeric, complex, character or logical vector from which
    to choose.}
  \item{size}{Non-negative integer giving the number of items to choose.}
  \item{replace}{Should sampling be with replacement?}
  \item{prob}{A vector of probability weights for obtaining the elements of
    the vector being sampled.}
}
\details{
  \code{resample} differs from the S/R \code{sample} function in
  \code{resample} always considers \code{x} to be a vector of elements
  to select from, while \code{sample} treats a vector of length one as a
  special case and samples from \code{1:x}.  Otherwise, the functions
  have identical behavior.
}
\value{
  Vector of the same length as the input, with the elements permuted.
}
\author{Gregory R. Warnes \email{greg@warnes.net}}
\seealso{\code{\link{sample}}}
\examples{
## Sample behavior differs if first argument is scalar vs vector
sample(c(10))
sample(c(10, 10))

## Resample has the consistent behavior for both cases
resample(c(10))
resample(c(10, 10))
}
\keyword{misc}