Added an R-like sampling function.