% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/resample.R
\name{resample}
\alias{resample}
\alias{deal}
\alias{shuffle}
\alias{sample}
\alias{sample.default}
\alias{sample.data.frame}
\alias{sample.matrix}
\alias{sample.factor}
\alias{sample.lm}
\title{More Random Samples}
\usage{
resample(..., replace = TRUE)

deal(...)

shuffle(x, replace = FALSE, prob = NULL, groups = NULL, orig.ids = FALSE)

sample(x, size, replace = FALSE, ...)

\method{sample}{default}(
  x,
  size,
  replace = FALSE,
  prob = NULL,
  groups = NULL,
  orig.ids = FALSE,
  ...
)

\method{sample}{data.frame}(
  x,
  size,
  replace = FALSE,
  prob = NULL,
  groups = NULL,
  orig.ids = TRUE,
  fixed = names(x),
  shuffled = c(),
  invisibly.return = NULL,
  ...
)

\method{sample}{matrix}(
  x,
  size,
  replace = FALSE,
  prob = NULL,
  groups = NULL,
  orig.ids = FALSE,
  ...
)

\method{sample}{factor}(
  x,
  size,
  replace = FALSE,
  prob = NULL,
  groups = NULL,
  orig.ids = FALSE,
  drop.unused.levels = FALSE,
  ...
)

\method{sample}{lm}(
  x,
  size,
  replace = FALSE,
  prob = NULL,
  groups = NULL,
  orig.ids = FALSE,
  drop.unused.levels = FALSE,
  parametric = FALSE,
  transformation = NULL,
  ...
)
}
\arguments{
\item{\dots}{additional arguments passed to
\code{\link[base:sample]{base::sample()}}
or \code{\link[=sample]{sample()}}.}

\item{replace}{Should sampling be with replacement?}

\item{x}{Either a vector of one or more elements from which to choose, or a positive integer.}

\item{prob}{A vector of probability weights for obtaining the elements of the vector being sampled.}

\item{groups}{a vector (or variable in a data frame) specifying
groups to sample within. This will be recycled if necessary.}

\item{orig.ids}{a logical; should original ids be included in returned data frame?}

\item{size}{a non-negative integer giving the number of items to choose.}

\item{fixed}{a vector of column names.  These variables are shuffled en masse,
preserving associations among these columns.}

\item{shuffled}{a vector of column names.
these variables are reshuffled individually (within groups if \code{groups} is
specified), breaking associations among these columns.
examples.}

\item{invisibly.return}{a logical, should return be invisible?}

\item{drop.unused.levels}{a logical, should unused levels be dropped?}

\item{parametric}{A logical indicating whether the resampling should be done parametrically.}

\item{transformation}{NULL or a function providing a transformation to be applied to the
synthetic responses.  If NULL, an attempt it made to infer the appropriate transformation
from the original call as recorded in \code{x}.}
}
\description{
These functions simplify and unify sampling in various ways.
}
\details{
These functions are wrappers around \code{\link[=sample]{sample()}} providing different defaults and
natural names.
}
\examples{
# 100 Bernoulli trials -- no need for replace=TRUE
resample(0:1, 100)
tally(resample(0:1, 100))
if (require(mosaicData)) {
Small <- sample(KidsFeet, 10)
resample(Small)
tally(~ sex, data=resample(Small))
tally(~ sex, data=resample(Small))
# fixed marginals for sex
tally(~ sex, data=Small)
tally(~ sex, data=resample(Small, groups=sex)) 
# shuffled can be used to reshuffle some variables within groups
# orig.id shows where the values were in original data frame.
Small <- mutate(Small, 
   id1 = paste(sex,1:10, sep=":"),  
   id2 = paste(sex,1:10, sep=":"))
resample(Small, groups=sex, shuffled=c("id1","id2"))
}
deal(Cards, 13)    # A Bridge hand
shuffle(Cards)
model <- lm(width ~length * sex, data = KidsFeet)
KidsFeet |> head()
resample(model) |> head()
Boot <- do(500) * lm(width ~ length * sex, data = resample(KidsFeet))
df_stats(~ Intercept + length + sexG + length.sexG, data = Boot, sd)
head(Boot)
summary(coef(model))


}
