Skip to contents

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

Usage

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

Arguments

tbl

a Momocs object (Coo, Coe)

size

numeric how many shapes should we sample

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_n and to maintain generic compatibility

Value

a Momocs object of same class

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_frac(), select(), slice(), subsetize()

Examples


# samples 5 bottles no matter their type
sample_n(bot, 5)
#> Out (outlines)
#>   - 5 outlines, 165 +/- 21 coords (in $coo)
#>   - 2 classifiers (in $fac): 
#> # A tibble: 5 × 2
#>   type   fake 
#>   <fct>  <fct>
#> 1 whisky a    
#> 2 whisky a    
#> 3 whisky b    
#> 4 whisky a    
#> 5 whisky a    
#>   - also: $ldk
# 5 bottles of beer and of whisky
table(sample_n(bot, 5, fac="type")$type)
#> 
#>   beer whisky 
#>      5      5 
# many repetitions
table(names(sample_n(bot, 400, replace=TRUE)))
#> 
#>          amrut    ballantines         brahma      bushmills          caney 
#>              9              8              8             10             11 
#>         chimay         chivas         corona        dalmore    deusventrue 
#>             14              9             16             17              6 
#>          duvel   famousgrouse   franziskaner    glendronach   glenmorangie 
#>             11             13             11             14             11 
#>     grimbergen        guiness   highlandpark     hoegardeen    jackdaniels 
#>              8              7              9              9              8 
#>             jb  johnniewalker        jupiler     kingfisher       latrappe 
#>             11             10             11             14             14 
#> lindemanskriek       magallan     makersmark    nicechouffe           oban 
#>              7             17              6              4              7 
#>     oldpotrero     pecheresse      redbreast   sierranevada         tamdhu 
#>             10             10             14              9             10 
#>     tanglefoot          tauro      westmalle     wildturkey         yoichi 
#>              6              4              7             12              8