exchange: Exchange two random elements in a matrix

Description Usage Arguments Value Examples

View source: R/exchange.R

Description

exchange returns a new matrix by switching two randomly selected elements from a user-defined matrix

Usage

1
exchange(X, j, type = "col")

Arguments

X

A matrix object. In general, X stands for a design matrix.

j

A positive integer, which stands for the j^th column (or row) of X, and it should be within [1,ncol(X)] (or [1,nrow(X)]).

type

An exchange type. If type is "col" (the default setting), two random elements will be exchanged within column j. If type is "row", two random elements will be exchanged within row j.

Value

If all inputs are logical, then the output will be a new design matrix after the exchange.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#create a toy LHD with 5 rows and 3 columns
toy=rLHD(n=5,k=3);toy

#Choose the first column of toy and exchange two randomly selected elements.
try.col=exchange(X=toy,j=1,type="col")
toy;try.col

#Choose the first row of toy and exchange two randomly selected elements.
try.row=exchange(X=toy,j=1,type="row")
toy;try.row

LHD documentation built on Aug. 1, 2021, 1:06 a.m.