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

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
#> 39           4.4         3.0          1.3         0.2     setosa
#> 32           5.4         3.4          1.5         0.4     setosa
#> 9            4.4         2.9          1.4         0.2     setosa
#> 12           4.8         3.4          1.6         0.2     setosa
#> 54           5.5         2.3          4.0         1.3 versicolor
#> 73           6.3         2.5          4.9         1.5 versicolor
#> 114          5.7         2.5          5.0         2.0  virginica
#> 85           5.4         3.0          4.5         1.5 versicolor
#> 52           6.4         3.2          4.5         1.5 versicolor
#> 3            4.7         3.2          1.3         0.2     setosa

sample_df(iris, previous = TRUE)
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#> 39           4.4         3.0          1.3         0.2     setosa
#> 32           5.4         3.4          1.5         0.4     setosa
#> 9            4.4         2.9          1.4         0.2     setosa
#> 12           4.8         3.4          1.6         0.2     setosa
#> 54           5.5         2.3          4.0         1.3 versicolor
#> 73           6.3         2.5          4.9         1.5 versicolor
#> 114          5.7         2.5          5.0         2.0  virginica
#> 85           5.4         3.0          4.5         1.5 versicolor
#> 52           6.4         3.2          4.5         1.5 versicolor
#> 3            4.7         3.2          1.3         0.2     setosa