Learn R Programming

Momocs (version 1.1.6)

sample_frac: Samples a fraction of shapes in Momocs objects

Description

Sample a fraction of shapes from a Momocs object. See examples and ?dplyr::sample_n.

Usage

sample_frac(tbl, size, replace, fac, ...)

Arguments

tbl
a Momocs object (Coo, Coe)
size
numeric (0 < numeric <= 1) the fraction of shapes to select
replace
logical whether sample should be done with ot without replacement
fac
a column name if a $fac is defined; size is then applied within levels of this factor
...
additional arguments to dplyr::sample_frac and to maintain generic compatibility

See Also

Other handling functions: arrange, at_least, chop, combine, dissolve, filter, mutate, rename, rm_uncomplete, rw_fac, sample_n, select, slice, subset.Coo, transmute

Examples

Run this code

data(bot)
bot
# samples 50% of the bottles no matter their type
sample_frac(bot, 0.5)
# 80% bottles of beer and of whisky
table(sample_frac(bot, 0.8, fac="type"))
# bootstrap the same number of bootles of each type but with replacement
table(names(sample_frac(bot, 1, replace=TRUE)))

Run the code above in your browser using DataLab