如何生成组合矩阵 [英] How to generate a matrix of combinations

查看:49
本文介绍了如何生成组合矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 5 个项目,每个项目的值都可以是 1 或 -1.我想生成一个由可能组合的行组成的矩阵.项目的顺序无关紧要,组合的顺序无关紧要.我知道我可以机械地做到这一点,但我认为有人必须知道生成这个矩阵的捷径.如果这与其他问题类似,我深表歉意,但我找到的任何解决方案都无法以我的编程技能应用于这个特定问题.

I have 5 items each of which can take on the value of 1 or -1. I want to generate a matrix that consists of rows of the possible combinations. The order of the items does not matter and the order of the combinations does not matter. I know I could do this mechanically, but I thought that someone must know a shortcut to generating this matrix. I apologize if this is similar to other questions but none of the solutions I have found can be applied to this particular problem with my programming skills.

推荐答案

expand.grid(c(-1,1), c(-1,1), c(-1,1), c(-1,1), c(-1,1))

这篇关于如何生成组合矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆