sample_n_obs
From metacoder v0.1.2
by Zachary Foster
Sample n observations from taxmap
Randomly sample some number of observations from a taxmap
object. Weights can be
specified for observations or the taxa they are taxmap by.
See sample_n for the inspiration for this function.
Usage
sample_n_obs(.data, size, replace = FALSE, taxon_weight = NULL, obs_weight = NULL, use_supertaxa = TRUE, collapse_func = mean, ...)
Arguments
 .data
 (
taxmap
) The object to sample from.  size
 (
numeric
of length 1) The number of observations to sample.  replace
 (
logical
of length 1) IfTRUE
, sample with replacement.  taxon_weight
 (
numeric
) Nonnegative sampling weights of each taxon. Ifuse_supertaxa
isTRUE
, the weights for each taxon in an observation's classification are supplied tocollapse_func
to get the observation weight. The expression given is evaluated in the context oftaxon_data
. In other words, any column name that appears intaxon_data(.data)
can be used as if it was a vector on its own. Ifobs_weight
is also specified, the two weights are multiplied (aftertaxon_weight
for each observation is calculated).  obs_weight
 (
numeric
) Sampling weights of each observation. The expression given is evaluated in the context ofobs_data
. In other words, any column name that appears inobs_data(.data)
can be used as if it was a vector on its own. Iftaxon_weight
is also specified, the two weights are multiplied (aftertaxon_weight
for each observation is calculated).  use_supertaxa
 (
logical
of length 1) Affects how thetaxon_weight
is used. IfTRUE
, the weights for each taxon in an observation's classification are multiplied to get the observation weight. Otherwise, just the taxonomic level the observation is assign to it considered.  collapse_func
 (
function
of length 1) Iftaxon_weight
option is used andsupertaxa
isTRUE
, the weights for each taxon in an observation's classification are supplied tocollapse_func
to get the observation weight. This function should take numeric vector and return a single number.  ...
 Additional options are passed to
filter_obs
.
Value

An object of type
taxmap
See Also
Other dplyrlike functions: arrange_obs
,
arrange_taxa
, filter_obs
,
filter_taxa
, mutate_obs
,
mutate_taxa
, sample_frac_obs
,
sample_frac_taxa
,
sample_n_taxa
, select_obs
,
select_taxa
, transmute_obs
,
transmute_taxa
Examples
# Subsample without replacement, keeping all taxa
sample_n_obs(unite_ex_data_3, 100)
# Subsample without replacement and remove unsampled taxa
sample_n_obs(unite_ex_data_3, 100, unobserved = FALSE)
# Subsample with taxon weight
sample_n_obs(unite_ex_data_3, 100, unobserved = FALSE, taxon_weight = 1 / n_obs)
# Sample with replacement
sample_n_obs(unite_ex_data_3, 10000, replace = TRUE)
Community examples
Looks like there are no examples yet.