taxa (version 0.1.0)

obs_apply: Apply function to observations per taxon

Description

Apply a function to data for the observations for each taxon. This is similar to using obs() with lapply() or sapply().

obj$obs_apply(data, func, simplify = FALSE, value = NULL,
  subset = NULL, recursive = TRUE, ...)
obs_apply(obj, data, func, simplify = FALSE, value = NULL,
  subset = NULL, recursive = TRUE, ...)

Arguments

obj

The taxmap() object containing taxon information to be queried.

data

Either the name of something in obj$data that has taxon information or a an external object with taxon information. For tables, there must be a column named "taxon_id" and lists/vectors must be named by taxon ID.

func

(function) The function to apply.

simplify

(logical) If TRUE, convert lists to vectors.

value

What data to give to the function. This is usually the name of column in a table in obj$data. Any result of all_names(obj) can be used, but it usually only makes sense to use columns in the dataset specified by the data option. By default, the indexes of observation in data are returned.

subset

(character) Taxon IDs or indexes for which observation indexes will be returned. Default: All taxa in obj will be used.

recursive

(logical or numeric) If FALSE, only return the observation assigned to the specified input taxa, not subtaxa. If TRUE, return all the observations of every subtaxa, etc. Positive numbers indicate the number of ranks below the each taxon to get observations for 0 is equivalent to FALSE. Negative numbers are equivalent to TRUE.

...

Extra arguments are passed to the function.

Examples

Run this code
# NOT RUN {
# Find the average number of legs in each taxon
obs_apply(ex_taxmap, "info", mean, value = "n_legs", simplify = TRUE)

# One way to implement `n_obs` and find the number of observations per taxon
obs_apply(ex_taxmap, "info", length, simplify = TRUE)

# }

Run the code above in your browser using DataCamp Workspace