Learn R Programming

gRbase (version 1.7-5)

simulateArray: Simulate data from array

Description

Simulate data (slice of) an array.

Usage

simulateArray(x, nsim = 1, margin, value.margin)

Arguments

x
An array
nsim
Number of cases to simulate
margin, value.margin
Specification of slice of array to simulate from

Value

A matrix

Examples

Run this code

## 2x2 array
x <- parray(c("a","b"), levels=c(2,2), values=1:4)

## Simulate from entire array
s <-simulateArray(x,1000)
xtabs(~., as.data.frame(s))

## Simulate from slice defined by that dimension 1 is fixed at level 2
s <-simulateArray(x,6000,1,2)
xtabs(~., as.data.frame(s))

## 2x2x2 array
x <- parray(c("a","b","c"), levels=c(2,2,2), values=1:8)

## Simulate from entire array
s <-simulateArray(x,36000)
xtabs(~., as.data.frame(s))

## Simulate from slice defined by that dimension 3 is fixed at level 1
s <-simulateArray(x,10000,3,1)
xtabs(~., as.data.frame(s))

Run the code above in your browser using DataLab