Sample from this DataFrame
Description
Sample from this DataFrame
Usage
<DataFrame>$sample(
n = NULL,
...,
fraction = NULL,
with_replacement = FALSE,
shuffle = NULL,
seed = NULL
)
Arguments
n
|
Number of items to return. Accepts a scalar value or a Series;
expressions are not supported. Values are parsed as literals. Cannot be
used with fraction. Defaults to 1 if fraction
is NULL.
|
…
|
These dots are for future extensions and must be empty. |
fraction
|
Fraction of items to return. Accepts a scalar value or a Series;
expressions are not supported. Values are parsed as literals. Cannot be
used with n.
|
with_replacement
|
Allow values to be sampled more than once. |
shuffle
|
If TRUE, explicitly shuffle the sampled data points. If
FALSE, maintain their relative order. If NULL
(default), use a high-performance algorithm without guaranteeing an
order.
|
seed
|
Seed for the random number generator. If NULL (default), a
random seed is generated for each sample operation.
|
Value
A polars DataFrame
Examples
library("polars")
df <- pl$DataFrame(
foo = 1:3,
bar = 6:8,
ham = c("a", "b", "c")
)
df$sample(n = 2, seed = 0)
#> shape: (2, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ str │
#> ╞═════╪═════╪═════╡
#> │ 1 ┆ 6 ┆ a │
#> │ 2 ┆ 7 ┆ b │
#> └─────┴─────┴─────┘