Skip to contents

This function is useful to check a data set. It gives a random number of rows of the input data set.

Usage

sample_df(x, n = 10, previous = FALSE)

Arguments

x

A data set: either a vector, a matrix or a data frame.

n

The number of random rows/elements to sample randomly.

previous

Logical scalar. Whether the results of the previous draw should be returned.

Value

A data base (resp vector) with n rows (resp elements).

Author

Laurent Berge

Examples


sample_df(iris)
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#> 117          6.5         3.0          5.5         1.8  virginica
#> 139          6.0         3.0          4.8         1.8  virginica
#> 79           6.0         2.9          4.5         1.5 versicolor
#> 95           5.6         2.7          4.2         1.3 versicolor
#> 130          7.2         3.0          5.8         1.6  virginica
#> 127          6.2         2.8          4.8         1.8  virginica
#> 144          6.8         3.2          5.9         2.3  virginica
#> 110          7.2         3.6          6.1         2.5  virginica
#> 82           5.5         2.4          3.7         1.0 versicolor
#> 51           7.0         3.2          4.7         1.4 versicolor

sample_df(iris, previous = TRUE)
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#> 117          6.5         3.0          5.5         1.8  virginica
#> 139          6.0         3.0          4.8         1.8  virginica
#> 79           6.0         2.9          4.5         1.5 versicolor
#> 95           5.6         2.7          4.2         1.3 versicolor
#> 130          7.2         3.0          5.8         1.6  virginica
#> 127          6.2         2.8          4.8         1.8  virginica
#> 144          6.8         3.2          5.9         2.3  virginica
#> 110          7.2         3.6          6.1         2.5  virginica
#> 82           5.5         2.4          3.7         1.0 versicolor
#> 51           7.0         3.2          4.7         1.4 versicolor