combinations

Faster way to achieve filtering for all possible combinations

天涯浪子 提交于 2020-01-14 09:24:09
问题 Consider I have a data frame like this, set.seed(1) q<-100 df <- data.frame(Var1 = round(runif(q,1,50)), Var2 = round(runif(q,1,50)), Var3 = round(runif(q,1,50)), Var4 = round(runif(q,1,50))) attach(df) As you realized, q is standing for setting the length of the each columns in the dataframe. I want to make a filtering of all possible combinations of the columns. It can be anything. Let's say I am seeking for if the devision of the sums of the first two columns and the sums of the last two

How to find all combinations (subset) of any size of an array in postgresql [duplicate]

本秂侑毒 提交于 2020-01-14 03:08:08
问题 This question already has an answer here : Array combinations without repetition (1 answer) Closed 5 years ago . Given an array, how to find all combinations (subsets) of elements of a certain size in postgresql. For example, given an array [1, 2, 3, 4] all combinations of size 3 would be [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4] Order is not important in combinations and therefore [1, 2, 3] and [3, 2, 1] are considered the same combination. Update: The size of the combinations required must

How to map combinations of things to a relational database?

允我心安 提交于 2020-01-13 11:35:30
问题 I have a table whose records represent certain objects. For the sake of simplicity I am going to assume that the table only has one column, and that is the unique ObjectId . Now I need a way to store combinations of objects from that table. The combinations have to be unique, but can be of arbitrary length. For example, if I have the ObjectId s 1,2,3,4 I want to store the following combinations: {1,2}, {1,3,4}, {2,4}, {1,2,3,4} The ordering is not necessary. My current implementation is to

Determine list of all possible products from a list of integers in Python

情到浓时终转凉″ 提交于 2020-01-13 07:30:10
问题 In Python 2.7 I need a method that returns all possible products of a list or tuple of int . Ie. if input is (2, 2, 3, 4) , then I'd want a output like (3, 4, 4) , 2 * 2 = 4 (2, 4, 6) , 2 * 3 = 6 (2, 3, 8) , 2 * 4 = 8 (3, 4, 4) , 2 * 2 = 4 (2, 2, 12) , 3 * 4 = 12 (2, 24) , 2 * 3 * 4 = 24 (3, 16) , 2 * 2 * 4 = 16 (4, 12) , 2 * 2 * 3 = 12 (48) , 2 * 2 * 3 * 4 = 48 wrapped up in a list or tuple . I figure that a nice implementation is probably possible using combinations from itertools , but I'd

All permutations with repetition using scala

梦想的初衷 提交于 2020-01-12 17:31:31
问题 I am looking for the scala way to give all permutations without repetitions. I know there are some postings on this site already but they seem to have a slightly different problem. I am searching for all permutations with repetitions. For example: combine(List('A','C','G')) Should yield: List(List('A'.'A','A'),List('A'.'A','C'),List('A'.'A','G'),List('A'.'C','A'), List('A'.'C',''C), ... List('G'.'G','G') I am sorry if my problem is already solved but I was not able to find it. Thanks in

All permutations with repetition using scala

落爺英雄遲暮 提交于 2020-01-12 17:30:43
问题 I am looking for the scala way to give all permutations without repetitions. I know there are some postings on this site already but they seem to have a slightly different problem. I am searching for all permutations with repetitions. For example: combine(List('A','C','G')) Should yield: List(List('A'.'A','A'),List('A'.'A','C'),List('A'.'A','G'),List('A'.'C','A'), List('A'.'C',''C), ... List('G'.'G','G') I am sorry if my problem is already solved but I was not able to find it. Thanks in

Find consecutive combinations [duplicate]

混江龙づ霸主 提交于 2020-01-12 09:15:18
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Rolling or sliding window iterator in Python I'm new to programming and am learning Python. I'm looking for an efficient/pythonic way to solve a problem. I'd like a function that returns a list of iterables containing the combinations of a parent iterable as long as the elements in the combination appear the same same consecutive order as the original parent iterable. I'm not sure if "consecutive" if the right

in R: find observations with unique combinations across columns, regardless their order [duplicate]

随声附和 提交于 2020-01-11 13:24:11
问题 This question already has an answer here : Select equivalent rows [A-B & B-A] [duplicate] (1 answer) Closed 3 years ago . I have a data frame with 1000 observations on 20 variables. I want to select only the rows that have a unique combination across columns, regardless of their order. That is, if a combination is ABA and another is BAA , I want the code only to return one of these combinations. To identify unique combinations I run a simple unique command across multiple variables. How would

combination from different vectors

一笑奈何 提交于 2020-01-11 12:50:08
问题 I have some vectors like this V1 = c(1,2,3,4,5) V2 = c(7,8,9,10,11) V3 = c(15,16,17,18,19) V4 = c(3,4,5,6,7) I would like to get all possible combinations from these vectors that look like this [V1[i],V2[j],V3[k],v4[z]] and that sums up to 3+9+17+5. This is a bit different from the duplicate R: sample() command subject to a constraint because I would like to get all combinations with one element from each vector and not get all combination from one vector. A possible solution should have one

Splitting triplicates into duplicates

为君一笑 提交于 2020-01-11 10:53:07
问题 I am wanting to split sets of triplicate results into the three possible duplicates. If the initial set is A B C 1 122 106 114 2 110 122 110 I want to transform it into A B 1 122 106 2 122 114 3 106 114 4 110 122 5 110 110 6 122 110 The combn function will do it line by line but I cannot figure out how to apply it across the full dataframe (which can be quite large, I only used two lines for demonstration purposes.). 回答1: You can do the following: Use lapply() to apply your combn for each row