MINI MINI MANI MO
%
% Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
%
\name{sample}
\alias{sample}
\alias{sample_frac}
\alias{sample_n}
\title{Sample Rows from an \code{ore.frame} Object}
\usage{
sample_n(tbl, size, replace = FALSE, weight = NULL)
sample_frac(tbl, size = 1, replace = FALSE, weight = NULL)
}
\arguments{
\item{tbl}{An \code{\link[OREbase:ore.frame-class]{ore.frame}} object to sample.}
\item{size}{For \code{sample_n}, the number of rows to select.
For \code{sample_frac}, the fraction of rows to select.
If \code{tbl} is grouped, then \code{size} applies to each group.}
\item{replace}{Specify \code{TRUE} to sample with replacement or \code{FALSE}
to sample without replacement. The default is FALSE.}
\item{weight}{Sampling weights. This expression is evaluated in the
context of the input \code{ore.frame} or an \code{ore.number} object.
It must return a vector of non-negative numbers with the same length as
the input. Weights are automatically normalized to sum to 1.}
}
\description{
Samples an \code{ore.frame} object by a fixed number of rows or a fraction,
with optional arguments of a sample weight and whether or not to use
replacement.
}
\examples{
MTCARS <- ore.push(mtcars)
by_cyl <- group_by(MTCARS, cyl)
# Sample fixed number per group
sample_n(MTCARS, 10)
nrow(sample_n(MTCARS, 50, replace = TRUE))
sample_n(MTCARS, 10, weight = mpg)
sample_n(MTCARS, 10, weight = MTCARS[["mpg"]])
arrange(sample_n(by_cyl, 3), cyl, mpg)
arrange(summarise(sample_n(by_cyl, 10, replace = TRUE), n = n()), cyl)
arrange(summarise(sample_n(by_cyl, 3, weight = mpg/mean(mpg)), n = n()), cyl)
arrange(summarise(sample_n(by_cyl, 3, weight = by_cyl[["mpg"]]/mean(by_cyl[["mpg"]])), n = n()), cyl)
# Sample fixed fraction per group
nrow(sample_frac(MTCARS, 0.1))
nrow(sample_frac(MTCARS, 1.5, replace = TRUE))
nrow(sample_frac(MTCARS, 0.1, weight = 1/mpg))
arrange(summarise(sample_frac(by_cyl, 0.2), n = n()), cyl)
arrange(summarise(sample_frac(by_cyl, 1, replace = TRUE), n = n()), cyl)
}
OHA YOOOO