capply: Apply functions to elements of a cycle

capplyR Documentation

Apply functions to elements of a cycle

Description

Function capply() means “cycle apply” and is modelled on lapply(). It applies a function to every element in the cycles of its argument.

Usage

capply(X, fun, ...)

Arguments

X

Permutation, coerced to cycle

fun

Function to be applied to each element of X

...

Further arguments to fun()

Details

This function is just a convenience wrapper really.

Value

Returns a permutation in cycle form

Author(s)

Robin K. S. Hankin

Examples



(x <- rperm())
capply(x,function(x){x+100})
capply(x,rev)

all(is.id(capply(x,rev)*x))  # should be TRUE

capply(rcyc(20,5,9),order)

capply(rcyc(20,5,9),sample)  # still 5-cycles





permutations documentation built on March 7, 2023, 8:26 p.m.