Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

valid

Functions to validate permutations


Description

Functions to validate permutation objects: if valid, return TRUE and if not valid, generate a warning() and return FALSE.

Function singleword.valid() takes an integer vector, interpreted as a word, and checks that it is a permutation of seq_len(max(x)).

Function cycle.valid() takes a cyclist and checks for disjoint cycles of strictly positive integers with no repeats.

Usage

singleword_valid(w)
cyclist_valid(x)

Arguments

x

In function cycle_valid(), a cyclist

w

In function singleword_valid(), an integer vector

Value

Returns either TRUE, or stops with an informative error message

Author(s)

Robin K. S. Hankin

See Also

Examples

singleword_valid(sample(1:9))      # TRUE
singleword_valid(c(3L,4L,2L,1L))   # TRUE
singleword_valid(c(3,4,2,1))       # FALSE (not integer)
singleword_valid(c(3L,3L,2L,1L))   # FALSE (3 repeated)

cyclist_valid(list(c(1,8,2),c(3,6))) # TRUE
cyclist_valid(list(c(1,8,2),c(3,6))) # FALSE ('8' is repeated)
cyclist_valid(list(c(1,8,1),c(3,6))) # FALSE ('1' is repeated)
cyclist_valid(list(c(0,8,2),c(3,6))) # FALSE (zero element)

permutations

The Symmetric Group: Permutations of a Finite Set

v1.0-9
GPL-2
Authors
Robin K. S. Hankin [aut, cre] (<https://orcid.org/0000-0001-5982-0415>), Paul Egeler [ctb] (<https://orcid.org/0000-0001-6948-9498>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.