Set variable names for all variables in a draws
object. The
set_variables()
form is useful when using pipe operators.
variables(x, ...) <- value
# S3 method for draws_matrix
variables(x, with_indices = TRUE, ...) <- value
# S3 method for draws_array
variables(x, with_indices = TRUE, ...) <- value
# S3 method for draws_df
variables(x, with_indices = TRUE, ...) <- value
# S3 method for draws_list
variables(x, with_indices = TRUE, ...) <- value
# S3 method for draws_rvars
variables(x, with_indices = FALSE, ...) <- value
set_variables(x, variables, ...)
(draws) A draws
object or another R object for which the method
is defined.
Arguments passed to individual methods (if applicable).
(character vector) new variable names.
(logical) Should indices be included in variable
names? For example, if the object includes variables named "x[1]"
and
"x[2]"
, if TRUE
, c("x[1]", "x[2]")
is returned; if FALSE
, only "x"
is returned. Defaults to TRUE
for all formats except draws_rvars()
.
Returns a draws
object of the same format as x
, with
variables named as specified.
variables(x) <- value
allows you to modify the vector of variable names,
similar to how names(x) <- value
works for vectors and lists. For renaming
specific variables, set_variables(x, value)
works equivalently, but is more intuitive
when using the pipe operator.
For renaming specific variables, rename_variables()
may offer a more
convenient approach.
x <- example_draws()
variables(x)
#> [1] "mu" "tau" "theta[1]" "theta[2]" "theta[3]" "theta[4]"
#> [7] "theta[5]" "theta[6]" "theta[7]" "theta[8]"
nvariables(x)
#> [1] 10
variables(x) <- letters[1:nvariables(x)]
# or equivalently...
x <- set_variables(x, letters[1:nvariables(x)])