Filters variates (data rows) from an mcnode based on logical conditions,
similar to dplyr::filter(). Can return a new node in the mcmodule or
return a filtered mcnode directly.
Usage
mc_filter(
mcmodule = NULL,
mc_name = NULL,
...,
data = NULL,
mcnode = NULL,
name = NULL,
prefix = NULL,
filter_suffix = "filtered",
summary = TRUE
)Arguments
- mcmodule
(mcmodule object, optional). Module containing the node. Default: NULL.
- mc_name
(character, optional). Name of the mcnode in the module.
- ...
(expression). Logical conditions to filter by; evaluated in context of the data associated with the mcnode.
- data
(data frame, optional). Input data frame. Default: NULL.
- mcnode
(mcnode object, optional). mcnode to filter directly. Default: NULL.
- name
(character, optional). Name for the new filtered node when adding to mcmodule. If NULL, auto-generated from
mc_nameandfilter_suffix. Default: NULL.- prefix
(character, optional). Prefix for the auto-generated node name. Default: NULL.
- filter_suffix
(character). Suffix appended to auto-generated name. Default: "filtered".
- summary
(logical). If TRUE, compute summary statistics for the new node. Default: TRUE.
Value
Either:
Updated mcmodule with new filtered node (when mcmodule and
nameprovided).Filtered mcnode object (when only
dataandmcnodeprovided).
Either:
An updated mcmodule with a new filtered node (when mcmodule and name are provided)
A raw filtered mcnode object (when only data and mcnode are provided)
Details
Call signatures:
To add filtered node to mcmodule:
mc_filter(mcmodule, "node", conditions, name = "new_name")To return filtered mcnode only:
mc_filter(conditions, data = data, mcnode = mcnode)
Filter conditions work on variates (data rows); only rows meeting all conditions are retained in the resulting mcnode.
Examples
# Filter within an mcmodule and create new node
imports_mcmodule <- mc_filter(
imports_mcmodule,
"w_prev",
origin == "nord",
name = "w_prev_countryA"
)
# Filter and return raw mcnode (note: conditions before named args)
w_prev <- imports_mcmodule$node_list$w_prev$mcnode
w_prev_filtered <- mc_filter(
origin == "nord",
data = imports_data,
mcnode = w_prev
)
# Multiple filter conditions
imports_mcmodule <- mc_filter(
imports_mcmodule,
"w_prev",
origin == "nord",
pathogen == "virus",
name = "w_prev_countryA_virus"
)
#> Warning: Filter conditions resulted in zero rows
