vperm: Calculate all permutations of all combinations of a specified...

View source: R/vperm.R

vpermR Documentation

Calculate all permutations of all combinations of a specified size from a data object.

Description

This function first uses combn to generate combinations of the desired size, then calculates all permutations of all said combinations.

Usage

vperm(x, m, FUN = NULL, ...)

Arguments

x

vector source for combinations, or integer n for x <- seq_len(n)

m

number of elements to choose in making the combinations

FUN

function to be applied to each combination; default NULL means the identity, i.e., to return the combination (vector of length m)

...

Additional arguments, if any, required for the function FUN . See Details.

Details

NA values are considered as valid elements and will be processed just as they are in combn The input arguments are passed directly to combn but with one important exception. combn's argument "simplify" is forced to "TRUE" inside this function so as to allow the permutations to be more easily generated. If the user includes simplify = FALSE in the ... input, it will be overwritten.

Value

An array within which each row contains one of the permutations.

Author(s)

Carl Witthoft, with some code taken from Sven Hohenstein via Stack Overflow

See Also

intersect, the CRAN package sets, perms

Examples

x <- c(1:5,3,3,3,2,NA,NA)
xp <- vperm(x,4) #large array

vecsets documentation built on Aug. 29, 2023, 1:06 a.m.