Skip to contents

Sample elements from x with replacement to build a factor.

Usage

sample_fct(x, N, ...)

Arguments

x

(character vector or factor)
If character vector then it is also used as levels of the returned factor. If factor then the levels are used as the new levels.

N

(numeric)
Number of items to choose.

...

Additional arguments to be passed to sample.

Value

A factor of length N.

Examples

sample_fct(letters[1:3], 10)
#>  [1] c b c b c b b a a b
#> Levels: a b c
sample_fct(iris$Species, 10)
#>  [1] versicolor setosa     versicolor versicolor setosa     setosa    
#>  [7] versicolor versicolor versicolor setosa    
#> Levels: setosa versicolor virginica