Learn R Programming

qrng (version 0.0-9)

to_array: Compute Matrices to Arrays

Description

Converting higher-dimensional matrices of quasi-random numbers to arrays of specific formats.

Usage

to_array(x, f, format = c("(n*f,d)", "(n,f,d)"))

Value

(n * f, d)-matrix or (n, f, d)-array

depending on the chosen format.

Arguments

x

(\(n\),\(f\)\(d\))-matrix of quasi-random numbers to be converted.

f

factor \(f\ge 1\) dividing ncol{x}.

format

character string indicating the output format to which x should be converted.

Author

Marius Hofert

Details

to_array() is helpful for converting quasi-random numbers to time series paths.

See Also

korobov(), ghalton(), sobol().

Examples

Run this code
## Basic call
N <- 4 # replications
n <- 3 # time steps
d <- 2 # dimension
set.seed(271) # note: respected for the choice of 'randomize'
x <- sobol(N, d = n * d, randomize = "digital.shift") # higher-dim. Sobol'
stopifnot(dim(to_array(x, f = n)) == c(N * n, d)) # conversion and check
stopifnot(dim(to_array(x, f = n, format = "(n,f,d)")) == c(N, n, d))

## See how the conversion is done
(x <- matrix(1:(N * n * d), nrow = N, byrow = TRUE))
to_array(x, f = n) # => (n * d)-column x was blocked in n groups of size d each

Run the code above in your browser using DataLab