latin_sq: Latin square

Description Usage Arguments Details Value See Also Examples

View source: R/latin_square.R

Description

Generate latin squares, either randomly or ordered

Usage

1
latin_sq(n, random = TRUE, reduce = TRUE)

Arguments

n

integer; number of unique values (aka. symbols)

random

logical; should the square be generated randomly?

reduce

logical; should the square be in reduced form?

Details

Computation time increses rapidly with n. On my computer generating a random square with n=12 takes about ten minutes, marking the upper limit of practicability, or even stretching it a little. A latin square in reduced form will have elements in the first row and the first column in a sorted order. By setting reduced=TRUE the first row and the first column will always be 1:n.

Value

A square integer matrix of size n^2

See Also

indexvalue

Examples

1
2
3
4
5
6
7
set.seed(1)
ls <- latin_sq(9, reduce=TRUE)
image(ls, col=randcolours(ncol(ls)))

# The more "classic" representation with latin capital letters
ls[] <- LETTERS[ls]
ls

AkselA/R-ymse documentation built on March 21, 2020, 9:52 a.m.