variables {posterior}R Documentation

Get variable names from draws objects

Description

Get variable names from draws objects.

Usage

variables(x, ...)

## S3 method for class 'draws_matrix'
variables(x, reserved = FALSE, with_indices = TRUE, ...)

## S3 method for class 'draws_array'
variables(x, reserved = FALSE, with_indices = TRUE, ...)

## S3 method for class 'draws_df'
variables(x, reserved = FALSE, with_indices = TRUE, ...)

## S3 method for class 'draws_list'
variables(x, reserved = FALSE, with_indices = TRUE, ...)

## S3 method for class 'draws_rvars'
variables(x, reserved = FALSE, with_indices = FALSE, ...)

nvariables(x, ...)

Arguments

x

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

...

Arguments passed to individual methods (if applicable).

reserved

(logical) Should reserved variables be included in the output? Defaults to FALSE. See reserved_variables for an overview of currently reserved 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() returns a vector of all variable names, and nvariables() returns the number of variables.

Value

For variables(), a character vector.

For nvariables(), a scalar integer.

See Also

variables<-, rename_variables, draws-index

Examples

x <- example_draws()

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

[Package posterior version 1.6.0 Index]