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
#> 84           6.0         2.7          5.1         1.6 versicolor
#> 90           5.5         2.5          4.0         1.3 versicolor
#> 39           4.4         3.0          1.3         0.2     setosa
#> 104          6.3         2.9          5.6         1.8  virginica
#> 11           5.4         3.7          1.5         0.2     setosa
#> 123          7.7         2.8          6.7         2.0  virginica
#> 13           4.8         3.0          1.4         0.1     setosa
#> 63           6.0         2.2          4.0         1.0 versicolor
#> 20           5.1         3.8          1.5         0.3     setosa
#> 71           5.9         3.2          4.8         1.8 versicolor

sample_df(iris, previous = TRUE)
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#> 84           6.0         2.7          5.1         1.6 versicolor
#> 90           5.5         2.5          4.0         1.3 versicolor
#> 39           4.4         3.0          1.3         0.2     setosa
#> 104          6.3         2.9          5.6         1.8  virginica
#> 11           5.4         3.7          1.5         0.2     setosa
#> 123          7.7         2.8          6.7         2.0  virginica
#> 13           4.8         3.0          1.4         0.1     setosa
#> 63           6.0         2.2          4.0         1.0 versicolor
#> 20           5.1         3.8          1.5         0.3     setosa
#> 71           5.9         3.2          4.8         1.8 versicolor