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

Examples


# samples 5 bottles no matter their type
sample_n(bot, 5)
#> Out (outlines)
#>   - 5 outlines, 162 +/- 30 coords (in $coo)
#>   - 2 classifiers (in $fac): 
#> # A tibble: 5 × 2
#>   type   fake 
#>   <fct>  <fct>
#> 1 whisky b    
#> 2 beer   d    
#> 3 beer   d    
#> 4 whisky a    
#> 5 whisky b    
#>   - 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 
#>              6              7              6             11             10 
#>         chimay         chivas         corona        dalmore    deusventrue 
#>             13             16             14             17             10 
#>          duvel   famousgrouse   franziskaner    glendronach   glenmorangie 
#>             14             15              8             12             12 
#>     grimbergen        guiness   highlandpark     hoegardeen    jackdaniels 
#>              7              5              8             10              7 
#>             jb  johnniewalker        jupiler     kingfisher       latrappe 
#>              7             14              9             13             10 
#> lindemanskriek       magallan     makersmark    nicechouffe           oban 
#>             11             11             11              9              8 
#>     oldpotrero     pecheresse      redbreast   sierranevada         tamdhu 
#>             10             10             14              8             10 
#>     tanglefoot          tauro      westmalle     wildturkey         yoichi 
#>              7              6              8             11              5