Learn R Programming

rvec (version 1.0.0)

pool_draws: 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 data.frame pool_draws(data, by = NULL)

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

Value

A data frame.

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.

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

Run this code
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)

Run the code above in your browser using DataLab