I have a vector with varying length, which can sometimes be of length 1.
I would like to sample from this vector such that if its length is 1 it always samples that 1 number.
sample() won’t do this because it samples from 1 to the digit when sample size is 1.
This is a documented feature:
An alternative is to write your own function to avoid the feature:
Some functions with similar behavior are listed under seq vs seq_along. When will using seq cause unintended results?