taxa (version 0.3.2)

sample_frac_obs: Sample a proportion of observations from taxmap()

Description

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, ...)

Arguments

obj

(taxmap()) The object to sample from.

data

Dataset names, indexes, or a logical vector that indicates which datasets in obj$data to sample. If multiple datasets are sample at once, then they must be the same length.

size

(numeric of length 1) The proportion of observations to sample.

replace

(logical of length 1) If TRUE, sample with replacement.

taxon_weight

(numeric) Non-negative sampling weights of each taxon. If use_supertaxa is TRUE, the weights for each taxon in an observation's classification are supplied to collapse_func to get the observation weight. If obs_weight is also specified, the two weights are multiplied (after taxon_weight for each observation is calculated).

obs_weight

(numeric) Sampling weights of each observation. If taxon_weight is also specified, the two weights are multiplied (after taxon_weight for each observation is calculated).

use_supertaxa

(logical or numeric of length 1) Affects how the taxon_weight is used. If TRUE, the weights for each taxon in an observation's classification are multiplied to get the observation weight. If FALSE just the taxonomic level the observation is assign to it considered. Positive numbers indicate the number of ranks above the each taxon to use. 0 is equivalent to FALSE. Negative numbers are equivalent to TRUE.

collapse_func

(function of length 1) If taxon_weight option is used and supertaxa is TRUE, the weights for each taxon in an observation's classification are supplied to collapse_func to get the observation weight. This function should take numeric vector and return a single number.

...

Additional options are passed to filter_obs().

target

DEPRECIATED. use "data" instead.

Value

An object of type taxmap()

See Also

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

Examples

Run this code
# NOT RUN {
# Sample half of the rows fram a table
sample_frac_obs(ex_taxmap, "info", 0.5)

# Sample multiple datasets at once
sample_frac_obs(ex_taxmap, c("info", "phylopic_ids", "foods"), 0.5)

# }

Run the code above in your browser using DataCamp Workspace