Learn R Programming

greta (version 0.2.0)

structures: create data greta arrays

Description

These structures can be used to set up more complex models. For example, scalar parameters can be embedded in a greta array by first creating a greta array with zeros() or ones(), and then embedding the parameter value using greta's replacement syntax.

Usage

zeros(...)

ones(...)

greta_array(data = 0, dim = length(data))

Arguments

...

dimensions of the greta arrays to create

data

a vector giving data to fill the greta array. Other object types are coerced by as.vector.

dim

an integer vector giving the dimensions for the greta array to be created.

Value

a greta array object

Details

greta_array is a convenience function to create an R array with array and then coerce it to a greta array. I.e. it is equivalent to as_data(array(data, dim)).

Examples

Run this code
# NOT RUN {
# a 3 row, 4 column greta array of 0s
z <- zeros(3, 4)

# a 3x3x3 greta array of 1s
z <- ones(3, 3, 3)

# a 2x4 greta array filled with pi
z <- greta_array(pi, dim = c(2, 4))

# a 3x3x3 greta array filled with 1, 2, and 3
z <- greta_array(1:3, dim = c(3, 3, 3))
# }

Run the code above in your browser using DataLab