Learn R Programming

nptest (version 1.2)

flipn: Generate All Sign-Flips of n Elements

Description

Generates all \(2^n\) vectors of length \(n\) consisting of the elements -1 and 1.

Usage

flipn(n)

Value

Matrix of dimension \(n\) by \(2^n\) where each column contains a unique sign-flip vector.

Arguments

n

Number of elements.

Author

Nathaniel E. Helwig <helwig@umn.edu>

Warning

For large n this function will consume a lot of memory and may even crash R.

Details

Adapted from the "bincombinations" function in the e1071 R package.

References

Meyer, D., Dimitriadou, E., Hornik, K., Weingessel, A., & Leisch, F. (2018). e1071: Misc Functions of the Department of Statistics, Probability Theory Group (Formerly: E1071), TU Wien. R package version 1.7-0. https://CRAN.R-project.org/package=e1071

Examples

Run this code
flipn(2)
flipn(3)

Run the code above in your browser using DataLab