Learn R Programming

posterior (version 1.6.0)

variables: Get variable names from draws objects

Description

Get variable names from draws objects.

Usage

variables(x, ...)

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

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

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

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

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

nvariables(x, ...)

Value

For variables(), a character vector.

For nvariables(), a scalar integer.

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.

See Also

variables<-, rename_variables, draws-index

Examples

Run this code
x <- example_draws()

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

Run the code above in your browser using DataLab