Skip to contents

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

Value

a Momocs object of same class

Note

the resulting fraction is rounded with ceiling.

See also

Other handling functions: arrange(), at_least(), chop(), combine(), dissolve(), fac_dispatcher(), filter(), mutate(), rename(), rescale(), rm_harm(), rm_missing(), rm_uncomplete(), rw_fac(), sample_n(), select(), slice(), subsetize()

Examples


# samples 50% of the bottles no matter their type
sample_frac(bot, 0.5)
#> Out (outlines)
#>   - 20 outlines, 158 +/- 22 coords (in $coo)
#>   - 2 classifiers (in $fac): 
#> # A tibble: 20 × 2
#>   type   fake 
#>   <fct>  <fct>
#> 1 beer   d    
#> 2 whisky a    
#> 3 beer   c    
#> 4 beer   d    
#> 5 beer   d    
#> 6 beer   d    
#> # ℹ 14 more rows
#>   - also: $ldk
# 80% bottles of beer and of whisky
table(sample_frac(bot, 0.8, fac="type")$fac)
#>         fake
#> type      a  b  c  d
#>   beer    0  0  7  9
#>   whisky 10  6  0  0
# bootstrap the same number of bootles of each type but with replacement
table(names(sample_frac(bot, 1, replace=TRUE)))
#> 
#>          amrut      bushmills          caney         chimay         chivas 
#>              1              2              1              1              2 
#>         corona        dalmore    deusventrue    glendronach   glenmorangie 
#>              1              1              2              2              1 
#>     grimbergen        guiness   highlandpark     hoegardeen    jackdaniels 
#>              1              2              2              1              1 
#>     kingfisher       latrappe lindemanskriek       magallan     makersmark 
#>              1              1              3              2              1 
#>    nicechouffe      redbreast         tamdhu      westmalle     wildturkey 
#>              1              1              1              1              2 
#>         yoichi 
#>              5