Take a sample of rows from a DataFrame
Description
Take a sample of rows from a DataFrame
Usage
<DataFrame>$sample(
n = NULL,
...,
fraction = NULL,
with_replacement = FALSE,
shuffle = FALSE,
seed = NULL
)
Arguments
n
|
Number of rows to return. Cannot be used with fraction .
|
…
|
Ignored. |
fraction
|
Fraction of rows to return. Cannot be used with n . Can be
larger than 1 if with_replacement is TRUE .
|
with_replacement
|
Allow values to be sampled more than once. |
shuffle
|
If TRUE , the order of the sampled rows will be shuffled. If
FALSE (default), the order of the returned rows will be
neither stable nor fully random.
|
seed
|
Seed for the random number generator. If set to NULL
(default), a random seed is generated for each sample operation.
|
Value
DataFrame
Examples
#> shape: (20, 5)
#> ┌──────────────┬─────────────┬──────────────┬─────────────┬────────────┐
#> │ Sepal.Length ┆ Sepal.Width ┆ Petal.Length ┆ Petal.Width ┆ Species │
#> │ --- ┆ --- ┆ --- ┆ --- ┆ --- │
#> │ f64 ┆ f64 ┆ f64 ┆ f64 ┆ cat │
#> ╞══════════════╪═════════════╪══════════════╪═════════════╪════════════╡
#> │ 6.9 ┆ 3.2 ┆ 5.7 ┆ 2.3 ┆ virginica │
#> │ 4.7 ┆ 3.2 ┆ 1.3 ┆ 0.2 ┆ setosa │
#> │ 4.8 ┆ 3.0 ┆ 1.4 ┆ 0.1 ┆ setosa │
#> │ 6.5 ┆ 3.0 ┆ 5.8 ┆ 2.2 ┆ virginica │
#> │ 5.2 ┆ 3.5 ┆ 1.5 ┆ 0.2 ┆ setosa │
#> │ … ┆ … ┆ … ┆ … ┆ … │
#> │ 4.8 ┆ 3.0 ┆ 1.4 ┆ 0.3 ┆ setosa │
#> │ 5.6 ┆ 3.0 ┆ 4.1 ┆ 1.3 ┆ versicolor │
#> │ 5.4 ┆ 3.7 ┆ 1.5 ┆ 0.2 ┆ setosa │
#> │ 6.3 ┆ 2.3 ┆ 4.4 ┆ 1.3 ┆ versicolor │
#> │ 6.3 ┆ 3.3 ┆ 4.7 ┆ 1.6 ┆ versicolor │
#> └──────────────┴─────────────┴──────────────┴─────────────┴────────────┘
#> shape: (15, 5)
#> ┌──────────────┬─────────────┬──────────────┬─────────────┬────────────┐
#> │ Sepal.Length ┆ Sepal.Width ┆ Petal.Length ┆ Petal.Width ┆ Species │
#> │ --- ┆ --- ┆ --- ┆ --- ┆ --- │
#> │ f64 ┆ f64 ┆ f64 ┆ f64 ┆ cat │
#> ╞══════════════╪═════════════╪══════════════╪═════════════╪════════════╡
#> │ 7.2 ┆ 3.6 ┆ 6.1 ┆ 2.5 ┆ virginica │
#> │ 4.5 ┆ 2.3 ┆ 1.3 ┆ 0.3 ┆ setosa │
#> │ 6.4 ┆ 3.2 ┆ 5.3 ┆ 2.3 ┆ virginica │
#> │ 7.3 ┆ 2.9 ┆ 6.3 ┆ 1.8 ┆ virginica │
#> │ 5.2 ┆ 3.5 ┆ 1.5 ┆ 0.2 ┆ setosa │
#> │ … ┆ … ┆ … ┆ … ┆ … │
#> │ 6.0 ┆ 3.4 ┆ 4.5 ┆ 1.6 ┆ versicolor │
#> │ 6.2 ┆ 3.4 ┆ 5.4 ┆ 2.3 ┆ virginica │
#> │ 5.2 ┆ 2.7 ┆ 3.9 ┆ 1.4 ┆ versicolor │
#> │ 5.9 ┆ 3.0 ┆ 5.1 ┆ 1.8 ┆ virginica │
#> │ 7.2 ┆ 3.2 ┆ 6.0 ┆ 1.8 ┆ virginica │
#> └──────────────┴─────────────┴──────────────┴─────────────┴────────────┘