sample_frac_taxa
From metacoder v0.1.2
by Zachary Foster
Sample a proportion of taxa from taxmap
Randomly sample some propoortion of taxa from a taxmap
object. Weights can be
specified for taxa or the observations assigned to them. See sample_frac for the
inspiration for this function.
Usage
sample_frac_taxa(.data, size = 1, taxon_weight = NULL, obs_weight = NULL, use_subtaxa = TRUE, collapse_func = mean, ...)
Arguments
 .data
 (
taxmap
) The object to sample from.  size
 (
numeric
of length 1) The proportion of taxa to sample.  taxon_weight
 (
numeric
) Nonnegative sampling weights of each taxon. 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 (afterobs_weight
for each taxon is calculated).  obs_weight
 (
numeric
) Sampling weights of each observation. The weights for each observation assigned to a given taxon are supplied tocollapse_func
to get the taxon weight. Ifuse_subtaxa
isTRUE
then the observations assigned to every subtaxa are also used. 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 (afterobs_weight
for each observation is calculated).  use_subtaxa
 (
logical
of length 1) Affects how theobs_weight
option 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
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_taxa
.
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_n_obs
, sample_n_taxa
,
select_obs
, select_taxa
,
transmute_obs
, transmute_taxa
Examples
# subsample taxa, preserving shared supertaxa
sample_frac_taxa(unite_ex_data_3, 0.1, supertaxa = TRUE)
# subsample taxa using weights, preserving subtaxa
sample_frac_taxa(unite_ex_data_3, 0.01, subtaxa = TRUE,
taxon_weight = ifelse(unite_rank == "g" & n_subtaxa > 3, 1, 0))
Community examples
Looks like there are no examples yet.