extract
returns a tibble of selected values
across the multiverse in a long format.
extract(...)
# S3 method for mverse
extract(
.mverse,
columns = NULL,
nuni = NULL,
frow = NULL,
include_branch_options = TRUE,
...
)
Ignored.
a mverse
object.
a character vector of column names to extract.
a positive integer for the number of universes to extract.
proportion of rows to extract from each universe.
when TRUE
(default), include the mutate
statements used to specified the options for each branched columns
a tibble containing the selected columns across the multiverse.
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.
# 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)
#> # A tibble: 1,128 × 5
#> universe hurricane_strength[,1] y hurricane_strength_branch y_branch
#> <fct> <dbl> <dbl> <fct> <fct>
#> 1 1 1590 2 hurricane_strength_1 y_1
#> 2 1 5350 4 hurricane_strength_1 y_1
#> 3 1 150 3 hurricane_strength_1 y_1
#> 4 1 58 1 hurricane_strength_1 y_1
#> 5 1 15 0 hurricane_strength_1 y_1
#> 6 1 19321 60 hurricane_strength_1 y_1
#> 7 1 3230 20 hurricane_strength_1 y_1
#> 8 1 24260 20 hurricane_strength_1 y_1
#> 9 1 2030 0 hurricane_strength_1 y_1
#> 10 1 14730 200 hurricane_strength_1 y_1
#> # ℹ 1,118 more rows
# 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"))
#> # A tibble: 1,128 × 4
#> universe hurricane_strength[,1] NDAM hurricane_strength_branch
#> <fct> <dbl> <dbl> <fct>
#> 1 1 1590 1590 hurricane_strength_1
#> 2 1 5350 5350 hurricane_strength_1
#> 3 1 150 150 hurricane_strength_1
#> 4 1 58 58 hurricane_strength_1
#> 5 1 15 15 hurricane_strength_1
#> 6 1 19321 19321 hurricane_strength_1
#> 7 1 3230 3230 hurricane_strength_1
#> 8 1 24260 24260 hurricane_strength_1
#> 9 1 2030 2030 hurricane_strength_1
#> 10 1 14730 14730 hurricane_strength_1
#> # ℹ 1,118 more rows
# Specify the universe to extract from using universe
extract(mv, universe = 1)
#> # A tibble: 1,128 × 5
#> universe hurricane_strength[,1] y hurricane_strength_branch y_branch
#> <fct> <dbl> <dbl> <fct> <fct>
#> 1 1 1590 2 hurricane_strength_1 y_1
#> 2 1 5350 4 hurricane_strength_1 y_1
#> 3 1 150 3 hurricane_strength_1 y_1
#> 4 1 58 1 hurricane_strength_1 y_1
#> 5 1 15 0 hurricane_strength_1 y_1
#> 6 1 19321 60 hurricane_strength_1 y_1
#> 7 1 3230 20 hurricane_strength_1 y_1
#> 8 1 24260 20 hurricane_strength_1 y_1
#> 9 1 2030 0 hurricane_strength_1 y_1
#> 10 1 14730 200 hurricane_strength_1 y_1
#> # ℹ 1,118 more rows
# Specify the number of universes to extract from using nuni
# The universes are randomly selected
extract(mv, nuni = 3)
#> # A tibble: 282 × 5
#> universe hurricane_strength[,1] y hurricane_strength_branch y_branch
#> <fct> <dbl> <dbl> <fct> <fct>
#> 1 11 0.217 2 hurricane_strength_6 y_1
#> 2 11 0.473 4 hurricane_strength_6 y_1
#> 3 11 -1.06 3 hurricane_strength_6 y_1
#> 4 11 -1.17 1 hurricane_strength_6 y_1
#> 5 11 -1.06 0 hurricane_strength_6 y_1
#> 6 11 0.217 60 hurricane_strength_6 y_1
#> 7 11 0.524 20 hurricane_strength_6 y_1
#> 8 11 1.34 20 hurricane_strength_6 y_1
#> 9 11 0.114 0 hurricane_strength_6 y_1
#> 10 11 -1.17 200 hurricane_strength_6 y_1
#> # ℹ 272 more rows
# Specify the proportion of data to extract from each universe using
# frow. The rows are randomly selected
extract(mv, frow = 0.7)
#> # A tibble: 792 × 5
#> universe hurricane_strength[,1] y hurricane_strength_branch y_branch
#> <fct> <dbl> <dbl> <fct> <fct>
#> 1 1 19321 60 hurricane_strength_1 y_1
#> 2 1 200 0 hurricane_strength_1 y_1
#> 3 1 1310 5 hurricane_strength_1 y_1
#> 4 1 20370 84 hurricane_strength_1 y_1
#> 5 1 510 22 hurricane_strength_1 y_1
#> 6 1 15 0 hurricane_strength_1 y_1
#> 7 1 5 1 hurricane_strength_1 y_1
#> 8 1 35 0 hurricane_strength_1 y_1
#> 9 1 410 3 hurricane_strength_1 y_1
#> 10 1 99 3 hurricane_strength_1 y_1
#> # ℹ 782 more rows