• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to generate a list of all combinations of 14 numbers into two separate groups?

Resolved: How to generate a list of all combinations of 14 numbers into two separate groups?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

So I am trying to create a list of all combinations of 14 numbers that have been split into two separate groups. For example, the beginning of this list may look like:
Group X Group Y
1 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
1, 2 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
1, 2, 3 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14

And so forth. This list would consist of 16384 possible combinations of these 14 numbers when split into two groups. (2^14) Any ideas on how to do this in R?

Answer:

You may try (for 2^3 cases)

x <- expand.grid(replicate(3, c(T,F), simplify = F)) apply(x, 1, function(x){list(group1 = c(1:3)[x], group2 = c(1:3)[!x])}) [[1]] [[1]]$group1 [1] 1 2 3 [[1]]$group2 numeric(0) [[2]] [[2]]$group1 [1] 2 3 [[2]]$group2 [1] 1 [[3]] [[3]]$group1 [1] 1 3 [[3]]$group2 [1] 2 [[4]] [[4]]$group1 [1] 3 [[4]]$group2 [1] 1 2 [[5]] [[5]]$group1 [1] 1 2 [[5]]$group2 [1] 3 [[6]] [[6]]$group1 [1] 2 [[6]]$group2 [1] 1 3 [[7]] [[7]]$group1 [1] 1 [[7]]$group2 [1] 2 3 [[8]] [[8]]$group1 numeric(0) [[8]]$group2 [1] 1 2 3 [/code]

If you have better answer, please add a comment about this, thank you!

list probability r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Resolved: std::regex_replace to replace multiple combinations

26/03/2023

Resolved: How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.