extract {mverse}R Documentation

Extract branched values.

Description

extract returns a tibble of selected values across the multiverse in a long format.

Usage

extract(...)

## S3 method for class 'mverse'
extract(
  .mverse,
  columns = NULL,
  nuni = NULL,
  frow = NULL,
  include_branch_options = TRUE,
  ...
)

Arguments

...

Ignored.

.mverse

a mverse object.

columns

a character vector of column names to extract.

nuni

a positive integer for the number of universes to extract.

frow

proportion of rows to extract from each universe.

include_branch_options

when TRUE (default), include the mutate statements used to specified the options for each branched columns

Details

This method extracts data values across the multiverse. You can specify a subset of data to extract using columns, universe, nuni, and frow.

You can specify the columns to extract from each universe by passing the column names as a character vector to columns. The default values is NULL extracting all columns with branches.

Use universe to specify a set of universes by their integer ids. Use nuni to specify the number of universes to extract data from. The method then selects the subset randomly. Specifying universe manually will override nuni value. By default, they are both set to NULL and the method returns data from all universes.

Use frow to randomly extract a fraction of data from each universe. The default value is NULL and all rows are returned as they are. Note if you select 1 the method will return shuffle rows in each universe before returning them. If frow is greater than 1, the method randomly samples rows with replacement.

Value

a tibble containing the selected columns across the multiverse.

Examples

# Define mutate branches.
hurricane_strength <- mutate_branch(
  # damage vs. wind speed vs.pressure
  NDAM,
  HighestWindSpeed,
  Minpressure_Updated_2014,
  # Standardized versions
  scale(NDAM),
  scale(HighestWindSpeed),
  -scale(Minpressure_Updated_2014),
)
y <- mutate_branch(
  alldeaths, log(alldeaths + 1)
)
# Create a mverse and add the branches.
mv <- create_multiverse(hurricane) %>%
  add_mutate_branch(hurricane_strength, y)
execute_multiverse(mv)
# Extract all branched columns from all universes
extract(mv)
# Specify the columns to extract from each universe using columns
# You can select both branched and non-branched columns
extract(mv, columns = c("hurricane_strength", "NDAM"))
# Specify the universe to extract from using universe
extract(mv, universe = 1)
# Specify the number of universes to extract from using nuni
# The universes are randomly selected
extract(mv, nuni = 3)
# Specify the proportion of data to extract from each universe using
# frow. The rows are randomly selected
extract(mv, frow = 0.7)

[Package mverse version 0.1.0 Index]