sampleIn: Sample from/in a design object

View source: R/GridData.R

sampleInR Documentation

Sample from/in a design object

Description

Sample from/in a design object.

Usage

sampleIn(X, size = 1L, atSample = FALSE, ...)

## S4 method for signature 'matrix'
sampleIn(X, size = 1L, atSample = FALSE, ...)

## S4 method for signature 'data.frame'
sampleIn(X, size = 1L, atSample = FALSE, ...)

## S4 method for signature 'Grid'
sampleIn(X, size = 1L, atSample = FALSE, ...)

Arguments

X

design Grid

size

Number of sample points.

atSample

should new sample points obtained using sample

...

optional args passed to 'sample()'

Details

From the object, size 'new' design points are sampled or drawn. When atSample is FALSE, the range of each column is computed or extracted from the object x, and then independent drawings from the corresponding uniform distributions are used.

Value

A matrix with size rows. When atSample is TRUE, the matrix has an attribute named index which gives the position of the sampled items in the original grid.

Note

When x is of class "Grid", it may be the case that the drawings with atSample = FALSE have no meaning since some of the variables may be discrete variables and not continuous ones.

See Also

The sample function.

Examples

g <- Grid(levels = list("Temp" = c(400, 450, 500),
                        "Bore" = c(0, 600, 1200, 1800, 2400)))
X1 <- sampleIn(g, size = 4)
X2 <- sampleIn(g, size = 4, atSample = TRUE)

## this must be zero
sum(abs(as.matrix(g)[attr(X2, "index"), ] - X2))




IRSN/smint documentation built on Dec. 9, 2023, 9:53 p.m.