\Header{sample}{Random Samples and Permutations}
\keyword{distribution}{sample}
\begin{Usage}
\begin{verbatim}
sample(x, size, replace=FALSE, prob)
\end{verbatim}
\end{Usage}
\begin{Description}
\texttt{sample} takes a sample of the specified size from
the elements of \texttt{x} using either with or without replacement
sampling according to the value of \texttt{replace}.

By default \texttt{size} is equal to \texttt{length(x)}
so that \texttt{sample(x)} generates a random permutation
of the elements of \texttt{x}.

If \texttt{x} has length 1, sampling takes place from
\texttt{1:x}.

The optional \texttt{prob} agrument can be used to give a vector
of probabilities of obtaining the elements of the vector being
sampled.\end{Description}
\begin{Examples}
\begin{ExampleCode}
x <- 1:12
# a random permutation
sample(x)
# bootstrap sampling
sample(x,replace=TRUE)

# 100 Bernoulli trials
sample(c(0,1), 100, replace = TRUE)
\end{ExampleCode}
\end{Examples}

