Randomly sample some proportion of observations from a taxmap()
object. Weights can be specified for observations or their taxa. See
dplyr::sample_frac()
for the inspiration for this function. Calling the
function using the obj$sample_frac_obs(...)
style edits "obj" in place, unlike
most R functions. However, calling the function using the sample_frac_obs(obj, ...)
imitates R's traditional copy-on-modify semantics, so "obj" would not
be changed; instead a changed version would be returned, like most R
functions.
obj$sample_frac_obs(data, size, replace = FALSE, taxon_weight = NULL, obs_weight = NULL, use_supertaxa = TRUE, collapse_func = mean, ...) sample_frac_obs(obj, data, size, replace = FALSE, taxon_weight = NULL, obs_weight = NULL, use_supertaxa = TRUE, collapse_func = mean, ...)
obj | ( |
---|---|
data | Dataset names, indexes, or a logical vector that indicates which datasets in
|
size | ( |
replace | ( |
taxon_weight | ( |
obs_weight | ( |
use_supertaxa | ( |
collapse_func | ( |
... | Additional options are passed to |
target | DEPRECIATED. use "data" instead. |
An object of type taxmap()
Other taxmap manipulation functions:
arrange_obs()
,
arrange_taxa()
,
filter_obs()
,
filter_taxa()
,
mutate_obs()
,
sample_frac_taxa()
,
sample_n_obs()
,
sample_n_taxa()
,
select_obs()
,
transmute_obs()
# Sample half of the rows fram a table sample_frac_obs(ex_taxmap, "info", 0.5)#> <Taxmap> #> 17 taxa: b. Mammalia, c. Plantae ... q. lycopersicum, r. tuberosum #> 17 edges: NA->b, NA->c, b->d, b->e ... j->o, k->p, l->q, l->r #> 4 data sets: #> info: #> # A tibble: 3 x 4 #> taxon_id name n_legs dangerous #> <chr> <chr> <dbl> <lgl> #> 1 n cat 4 FALSE #> 2 m tiger 4 TRUE #> 3 q tomato 0 FALSE #> phylopic_ids: a named vector of 'character' with 6 items #> m. e148eabb-f138-43[truncated] ... r. 63604565-0406-46[truncated] #> foods: a list of 6 items named by taxa: #> m, n, o, p, q, r #> abund: #> # A tibble: 8 x 5 #> taxon_id code sample_id count taxon_index #> <chr> <fct> <fct> <dbl> <int> #> 1 m T A 1 1 #> 2 n C A 2 2 #> 3 o M B 5 3 #> # … with 5 more rows #> 1 functions: #> reaction# Sample multiple datasets at once sample_frac_obs(ex_taxmap, c("info", "phylopic_ids", "foods"), 0.5)#> <Taxmap> #> 17 taxa: b. Mammalia, c. Plantae ... q. lycopersicum, r. tuberosum #> 17 edges: NA->b, NA->c, b->d, b->e ... j->o, k->p, l->q, l->r #> 4 data sets: #> info: #> # A tibble: 3 x 4 #> taxon_id name n_legs dangerous #> <chr> <chr> <dbl> <lgl> #> 1 n cat 4 FALSE #> 2 o mole 4 FALSE #> 3 q tomato 0 FALSE #> phylopic_ids: a named vector of 'character' with 3 items #> n. 12899ba0-9923-4f[truncated] ... q. b6400f39-345a-47[truncated] #> foods: a list of 3 items named by taxa: #> n, o, q #> abund: #> # A tibble: 8 x 5 #> taxon_id code sample_id count taxon_index #> <chr> <fct> <fct> <dbl> <int> #> 1 m T A 1 1 #> 2 n C A 2 2 #> 3 o M B 5 3 #> # … with 5 more rows #> 1 functions: #> reaction