variables<- {posterior}R Documentation

Set variable names in draws objects

Description

Set variable names for all variables in a draws object. The set_variables() form is useful when using pipe operators.

Usage

variables(x, ...) <- value

## S3 replacement method for class 'draws_matrix'
variables(x, with_indices = TRUE, ...) <- value

## S3 replacement method for class 'draws_array'
variables(x, with_indices = TRUE, ...) <- value

## S3 replacement method for class 'draws_df'
variables(x, with_indices = TRUE, ...) <- value

## S3 replacement method for class 'draws_list'
variables(x, with_indices = TRUE, ...) <- value

## S3 replacement method for class 'draws_rvars'
variables(x, with_indices = FALSE, ...) <- value

set_variables(x, variables, ...)

Arguments

x

(draws) A draws object or another R object for which the method is defined.

...

Arguments passed to individual methods (if applicable).

value, variables

(character vector) new variable names.

with_indices

(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().

Details

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.

Value

Returns a draws object of the same format as x, with variables named as specified.

See Also

variables, rename_variables, draws-index

Examples

x <- example_draws()

variables(x)
nvariables(x)
variables(x) <- letters[1:nvariables(x)]

# or equivalently...
x <- set_variables(x, letters[1:nvariables(x)])


[Package posterior version 1.6.0 Index]