permute: Space efficient unique permutation generation

Description Usage Arguments Details Value Author(s) Examples

Description

Efficiently generate truly unique and random permutations of binary data in R.

Usage

1
permute(original, number_permutations)

Arguments

original

an integer (0/1 only) or logical vector representing the statuses of the true observations.

number_permutations

integer; desired number of permutations to find.

Details

This function uses C++ bitsets to decrease memory load and random_shuffle to increase speed. It is capable of generating 1,000,000 unique permutations of a 1000 observation binary vector in around 30 seconds.

If you are getting errors while using this method it is likely because this method has a C++ implementation. Check to make sure that you have the necessary tools to compile C++ code.

Value

A 0/1 matrix with number_permutations rows and length(original) columns. If there are fewer possible permutations than are requested, will return as many as possible.

Author(s)

PJ Tatlow, Samantha Jensen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
example_states <- c(0,0,0,0,1,1,1,1)
permute(example_states, 34)

example_states <- c(rep(1, 500), rep(0,500))
permute(example_states, 1000)

#TIMING AND MEMORY USAGE EXAMPLES

library(R.utils) # for timing
library(profmem) # for memory usage information

ptm <- proc.time()
permute(example_states, 1000)
print(proc.time() - ptm)

print(total(profmem(permute(example_states, 1000))))

samanthaleejensen/uniqueperm documentation built on May 15, 2019, 5:52 p.m.