LHD (version 1.3.3)

exchange: Exchange two random elements in a matrix

Description

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

Usage

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

Run this code
# NOT RUN {
#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
# }

Run the code above in your browser using DataLab