nest_rvars | R Documentation |
rvar
columns in data framesConverts between data-frame-of-rvar
s format and long-data-frame-of-draws
formats by nesting or unnesting all columns containing posterior::rvar
objects.
nest_rvars(data)
unnest_rvars(data)
data |
A data frame to nest or unnest.
|
For nest_rvars()
, returns a data frame without .chain
, .iteration
, and
.draw
columns, where all non-grouped columns have been converted to rvar
s.
For unnest_rvars()
, returns a data frame with .chain
, .iteration
, and
.draw
columns added, where every rvar
column in the input has been
converted to (one or more) columns containing draws from those rvar
s
in long format. The result is grouped by all non-rvar
columns in the
input; this ensures that nest_rvars(unnest_rvars(x))
returns x
.
library(dplyr)
data(RankCorr, package = "ggdist")
# here's a data frame with some rvars
rvar_df = RankCorr %>%
spread_rvars(b[i,], tau[i])
rvar_df
# we can unnest it into long format.
# note how the result is grouped by all non-rvar input columns,
# and nested indices in `b` are converted into columns.
draws_df = rvar_df %>%
unnest_rvars()
draws_df
# calling nest_rvars() again on the result of unnest_rvars()
# recovers the original data frame
nest_rvars(draws_df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.