Learn R Programming

rv (version 2.3.2)

Extract.rv: Extract or Replace Parts of a Random Vector

Description

Bracket slice and assignment methods adapted for random vectors and arrays. The assignment function impute<- is compatible with both non-rv and rv objects (rv, rvsummary, and rvfactor objects). To write universal code that works both atomic and rv objects, use impute(x, ...) <- value instead of x[...] <- value.

Usage

# S3 method for rv
[(x, … , drop = TRUE)
# S3 method for rvfactor
[(x, … , drop = FALSE)
# S3 method for rvsummary
[(x, … , drop = TRUE)
# S3 method for rv
[(x, …) <- value
# S3 method for rvsummary
[(x, …) <- value
impute(x, …) <- value

Arguments

x
object from which to extract element(s) or in which to replace element(s).
indices specifying elements to extract or replace.
value
typically an array-like R object of a similar class as x.
drop
For matrices and arrays. If TRUE the result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement.

Value

A random variable (an rv object).

Details

NOTE. x will NOT be automatically coerced into an rv object. value may be an rv object or a regular numeric object. Extracting rv objects works the same way as extracting components of a numerical vector or array. The return value is always an object of class 'rv'. Type ?Extract for details. Note: the index arguments (i, j, etc.) must be constants, but this may change in the future.

References

Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244. See also vignette("rv").

Examples

Run this code
  x <- rvnorm(1)
  y <- (1:5)
  ## Not run: ------------------------------------
#      y[2] <- x ## Will not work
#   
## ---------------------------------------------
  impute(y, 2) <- x

Run the code above in your browser using DataLab