safesample: Safely Sample a Single Item

Description Usage Arguments Details Value Side effects References See Also Examples

Description

Single random selection from the input vector.

Usage

1

Arguments

x

a vector.

Details

This works around the infelicity of the sample function that can give the wrong result if x has length 1. See Circle 8.2.33 of 'The R Inferno'.

Value

a random element of the input x.

Side effects

modify the random seed.

References

http://www.burns-stat.com/documents/books/the-r-inferno/

See Also

sample.

Examples

1
2
3
4
5
6
safesample(2:6) # like 'sample(2:6, 1)'

safesample(4) # still works as intended

#compare:
sample(4)

TaoTeProgramming documentation built on May 1, 2019, 6:47 p.m.