safe_sample {netcutter}R Documentation

Sample one item from a vector, even when the vector has length 1

Description

Sample one item from a vector, even when the vector has length 1

Usage

safe_sample(x)

Arguments

x

Vector of values to sample

Details

When x has length 1, the sample() function thinks that we want to sample from 1 to x. However, we deal want to sample vectors of unknown length, and possibly of length 1, but we always want to sample among the values of x. This function ensures that.

Value

One value from x.


[Package netcutter version 0.3.1 Index]