taxa (version 0.1.0)

filter_obs: Filter observations with a list of conditions

Description

Filter data in a taxmap() object (in obj$data) with a set of conditions. See dplyr::filter() for the inspiration for this function and more information. Calling the function using the obj$filter_obs(...) style edits "obj" in place, unlike most R functions. However, calling the function using the filter_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$filter_obs(target, ..., drop_taxa = FALSE)
filter_obs(obj, target, ..., drop_taxa = FALSE)

Arguments

obj

An object of type taxmap()

target

The name of the list/vector/table in obj$data to filter

...

One or more filtering conditions. Any variable name that appears in all_names() can be used as if it was a vector on its own. Each filtering condition can be one of three things:

  • integer: One or more row indexes of obj[target]

  • logical: A TRUE/FALSE vector of length equal to the number of rows in obj[target]

drop_taxa

(logical of length 1) If FALSE, preserve taxa even if all of their observations are filtered out. If TRUE, remove taxa for which all observations were filtered out. Note that only taxa that are unobserved due to this filtering will be removed; there might be other taxa without observations to begin with that will not be removed.

Value

An object of type taxmap()

See Also

Other taxmap manipulation functions: arrange_obs, arrange_taxa, filter_taxa, mutate_obs, sample_frac_obs, sample_frac_taxa, sample_n_obs, sample_n_taxa, select_obs, transmute_obs

Examples

Run this code
# NOT RUN {
# Filter by row index
filter_obs(ex_taxmap, "info", 1:2)

# Filter by TRUE/FALSE
filter_obs(ex_taxmap, "info", dangerous == FALSE)

# Remove taxa whose obserservation were filtered out
filter_obs(ex_taxmap, "info", dangerous == FALSE, drop_taxa = TRUE)

# }

Run the code above in your browser using DataCamp Workspace