A generic function to generate a random permutation of an object. The default
method is equivalent to sample(x)
without surprises for numeric vectors of
length 1. The data.frame
method permutes the order of rows.
Examples
permute(1:5)
#> [1] 2 3 1 5 4
permute(5) # Compare to sample(5)
#> [1] 5
# The data.frame method permutes rows
permute(iris) |> head()
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 103 7.1 3.0 5.9 2.1 virginica
#> 21 5.4 3.4 1.7 0.2 setosa
#> 95 5.6 2.7 4.2 1.3 versicolor
#> 142 6.9 3.1 5.1 2.3 virginica
#> 112 6.4 2.7 5.3 1.9 virginica
#> 147 6.3 2.5 5.0 1.9 virginica