pool_draws: Pool Draws

View source: R/pool_draws.R

pool_drawsR Documentation

Pool Draws

Description

Combine draws within each combination of grouping or 'by' variables in a data frame.

Usage

pool_draws(data, by = NULL)

## S3 method for class 'data.frame'
pool_draws(data, by = NULL)

## S3 method for class 'grouped_df'
pool_draws(data, by = NULL)

Arguments

data

A data frame with one or more rvecs. Can be grouped.

by

The variables distingishing units after combining. Used if data is not grouped.

Details

Each combination of grouping or 'by' variables must have the same number of rows.

Value

A data frame.

See Also

  • collapse_to_rvec() Convert from 'draws-and-value' fromat to rvec format

  • expand_from_rvec() Convert from rvec format to 'draws-and-value' format

Examples

library(dplyr, warn.conflicts = FALSE)

df <-  tibble(
  a = c(1, 1, 2, 2),
  x = rvec(list(1:2, 3:4, 5:6, 7:8))
)
df
df |> pool_draws(by = a)
df |> group_by(a) |> pool_draws()
df |> pool_draws()

df_big <- tibble(
  a = c(1, 1, 2, 2, 1, 1, 2, 2),
  b = c(1, 1, 1, 1, 2, 2, 2, 2),
  x = rvec(list(1:2, 3:4, 5:6, 7:8,
                9:10, 11:12, 13:14, 15:16)),
  y = rvec(list(1:3, 4:6, 7:9, 10:12,
                13:15, 16:18, 19:21, 22:24))
)
df_big |> pool_draws(by = c(a, b))
df_big |> group_by(a, b) |> pool_draws()
df_big |> pool_draws(by = a)

rvec documentation built on Dec. 10, 2025, 5:08 p.m.