combinations

r: create data frame with all possible options and number of variable combinations

余生颓废 提交于 2019-12-12 09:05:52
问题 This question might be obvious or asked already, but I can't find a solution: I want to create a data frame with all possible combinations (and number of variables) such that it looks like the following example: dataframe <- data.frame(variable = 1:4, a = c("gender", NA, NA, NA), b = c("age", NA, NA, NA), c = c("city", NA, NA, NA), d = c("education", NA, NA, NA), e = c("gender", "age", NA, NA), f = c("gender", "city", NA, NA), g = c("gender", "education", NA, NA), h = c("age", "city", NA, NA)

PostgreSQL find all possible combinations (permutations) in recursive query

↘锁芯ラ 提交于 2019-12-12 08:53:22
问题 Input is an array of 'n' length. I need to generate all possible combinations of array elements, including all combinations with fewer elements from the input array. IN: j='{A, B, C ..}' OUT: k='{A, AB, AC, ABC, ACB, B, BA, BC, BAC, BCA..}' With repetitions, so with AB BA .. I have tried something like this: WITH RECURSIVE t(i) AS (SELECT * FROM unnest('{A,B,C}'::text[])) ,cte AS ( SELECT i AS combo, i, 1 AS ct FROM t UNION ALL SELECT cte.combo || t.i, t.i, ct + 1 FROM cte JOIN t ON t.i > cte

Efficient way to generate combinations ordered by increasing sum of indexes

Deadly 提交于 2019-12-12 08:26:55
问题 For a heuristic algorithm I need to evaluate, one after the other, the combinations of a certain set until I reach a stop criterion. Since they are a lot, at the moment I'm generating them using the following memory efficient iterator block (inspired by python's itertools.combinations): public static IEnumerable<T[]> GetCombinations<T>(this IList<T> pool, int r) { int n = pool.Count; if (r > n) throw new ArgumentException("r cannot be greater than pool size"); int[] indices = Enumerable.Range

Solve a simple packing combination with dependencies

删除回忆录丶 提交于 2019-12-12 08:06:38
问题 This is not a homework question, but something that came up from a project I am working on. The picture above is a packing configuration of a set of boxes, where A,B,C,D is on the first layer and E,F,G on the second layer. The question is that if the boxes are given in a random order, what is the probability that the boxes can be placed in the given configuration? The only condition for the placement is all the boxes need to be placed from top down and cannot be moved once placed. Therefore

How to loop through all the combinations of e.g. 48 choose 5 [duplicate]

烂漫一生 提交于 2019-12-12 07:56:53
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to iteratively generate k elements subsets from a set of size n in java? I want to build my own poker hand evaluator but am having trouble with a particular part. If two players get dealt a two card hand, then there will be 48 cards left in the pack. In Texas Hold'em a further 5 possible community cards are then dealt (this is called the board). I want to enumerate / loop through all the 48 choose 5 possible

How can i generate 4 bit binary combination using recursion in C for 0,1?

回眸只為那壹抹淺笑 提交于 2019-12-12 07:37:47
问题 For this array, trying something like this: void rollover(int val,int count) { if(count==0) { return; } printf("%d ",val); count--; rollover(val,count); } int main() { int arr[]={0,1}; for(int i=0;i<=1;i++) { rollover(arr[i],4); } printf("\n"); return 0; } Expected output using recursion method: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Can't understand how to write that rec function. I have spent several hours to solve it. Can someone assist to write

Select rows based on non-directed combinations of columns

梦想的初衷 提交于 2019-12-12 05:37:53
问题 I am trying to select the maximum value in a dataframe's third column based on the combinations of the values in the first two columns. My problem is similar to this one but I can't find a way to implement what I need. EDIT: Sample data changed to make the column names more obvious. Here is some sample data: library(tidyr) set.seed(1234) df <- data.frame(group1 = letters[1:4], group2 = letters[1:4]) df <- df %>% expand(group1, group2) df <- subset(df, subset = group1!=group2) df$score <-

How can I efficiently use threads in this case?

末鹿安然 提交于 2019-12-12 04:59:05
问题 I have to write in a file all possible combinations resulting from the lottery using threads. Example: 0 0 0 0 0 0 (first combination) 0 0 0 0 0 1 (Second combination) 0 0 0 0 0 2 . . . Last. 38 38 38 38 38 38 (Last combination) In my main class i just use one thread because i dont know how i can use more threads for write in the file faster. For generates the numbers i uses 6 loops one inside the other this way: import java.io.BufferedWriter; import java.io.File; import java.io

looping all number combinations

对着背影说爱祢 提交于 2019-12-12 04:56:55
问题 I'm working on a test function that is supposed to test values automaticly to see if there is an unexpected error. There are six "holders" that is supposed to have a value range between -999 to 1000 This is how I tried it: #include <stdlib.h> #include <stdio.h> int inuti(double x, double y, double x1, double y1, double x2, double y2) { int x_inuti; int y_inuti; if (x1 < x2) x_inuti = x > x1 && x < x2; else x_inuti = x > x2 && x < x1; if (y1 < y2) y_inuti = y > y1 && y < y2; else y_inuti = y >

Is there an easy way to match values of a list to array in R?

爱⌒轻易说出口 提交于 2019-12-12 04:45:08
问题 I have several (named) vectors in a list: data = list(a=runif(n = 50, min = 1, max = 10), b=runif(n = 50, min = 1, max = 10), c=runif(n = 50, min = 1, max = 10), d=runif(n = 50, min = 1, max = 10)) I want to play around with different combinations of them depending on what an array tells me, for example I want to sum across the different combinations in combs: var <- letters[1:length(data)] combs <- do.call(expand.grid, lapply(var, function(x) c("", x)))[-1,] And get the sums for each row of