Learn R Programming

smint (version 0.4.2)

sampleIn: Sample from/in a design object

Description

Sample from/in a design object.

Usage

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

Arguments

X
The object, typically a design matrix with class matrix or an object with class "Grid".
size
Number of sample points.
atSample
Logical. If TRUE the new sample points are obtained using sample
...
Other arguments to be passed to the sample function when atSample is TRUE, typically replace = TRUE is needed when the object x contains less than the target number given in size.

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.

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.

See Also

The sample function.

Examples

Run this code
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))

Run the code above in your browser using DataLab