Questions tagged [combn]
121 questions
0
votes
3 answers
Error in combn(unique(x), 2, paste, collapse = " and ") : n < m
I have a 185,686 rows data frame with 11 variables but I'm only interested in two: Order.ID and Product
Each line of the original data frame contains an unique combination of ID, product, quantity, adress, etc. From this df I created a new one that…

Eduardo Neiva
- 1
- 1
0
votes
2 answers
How to iterate column values to find out all possible combinations in R?
Suppose you have a dataframe with ids and elements prescripted to each id. For example:
example <- data.frame(id = c(1,1,1,1,1,2,2,2,3,4,4,4,4,4,4,4,5,5,5,5),
vals = c("a","b",'c','d','e','a','b','d','c',
…

rg4s
- 811
- 5
- 22
0
votes
1 answer
How to see which element (of length x) in a list is contained in which other element (of length x+1) of that list?
Say I have the following list:
unlist(mapply(combn, list(1:3), seq_along(1:3), simplify = FALSE), recursive = FALSE)
Now, I want to know for each element of length x in the list, in which other elements of length x+1 it is contained. Preferably, it…

Alexander
- 72
- 7
0
votes
1 answer
Finding the index of the vector for the sum of pairwise in R
When I run this code
x <- c(2, 2, 10, 8)
combn(x, 2, sum)
I get
> combn(x, 2, sum)
[1] 4 12 10 12 10 18
How do I get the index for x for any of the combn?
For this question, the 4 is the sum of 2 + 2 which is x[1] + x[2]. I need the index [1] and…

skadoosh
- 21
- 2
0
votes
2 answers
Running a combn function on different columns of a dataframe, one row at a time
I have the following data frame :
# A tibble: 3 x 4
index number_1 number_2 number_3
1 1 32 16 29
2 2 13 50 47
3 3 37 19 18
I would like to run a…

Frederi ROSE
- 297
- 2
- 9
0
votes
1 answer
How do use combn generally when pairs are not always possible?
I am looking for a generic method to deal with situations in which combinations are required, but when data does not always meet the assumptions of the combn function.
Specifically, I have a dataframe of members of Congress and their committee…

Ben
- 1,113
- 10
- 26
0
votes
1 answer
Get all combinations for a dynamic length of elements to select
I have a data frame:
dat <- data.frame(toys = c("bear", "car", "plane", "truck", "doll"),
price = c(1.23, 2.34, 3.45, 4.56, 5.67))
I now want to get all combinations of toys where I would select 2, 3 and 4 toys at a time.
I could…

deschen
- 10,012
- 3
- 27
- 50
0
votes
1 answer
R - maximum value of variables when compared between levels of variable1 grouped by variable2
Consider the following data
set.seed(123)
example.df <- data.frame(
gene = sample(c("A", "B", "C", "D"), 100, replace = TRUE),
treated = sample(c("Yes", "No"), 100, replace = TRUE),
resp=rnorm(100, 10,5), effect = rnorm (100, 25, 5))
I am trying…

jaydoc
- 79
- 1
- 7
0
votes
1 answer
Is there a more memory-efficient way to use combn to subtract every column from every other column in R?
I am trying to subtract each column from each other column in a large R data.table, that has 13125 columns and 90 rows.
I am following up on a previous question which addresses this for data.tables of smaller dimensions (Subtract every column from…

fields
- 1
0
votes
1 answer
How do I use combn for multiple regression (or an alternative)?
I want to get regression coefficients and fit statistics from one dependent regressed on all combinations of two other independent factors.
What I have is data like this (Note the NA):
H<-data.frame(replicate(10,sample(0:20,10,rep=TRUE)))…

CrunchyTopping
- 803
- 7
- 17
0
votes
1 answer
Applying combine function over dataframe and saving as a single list/dataframe
I am trying to create a network. I have a dataframe:
. . v1 .v2 .v3
1/ .1 ... 2.... 3
2/ .3 ... 4 .. 7
3/. 6 ...11 . 9
I wish to find all possible combinations within each row. For example, the 1st row has the values 1, 2, 3 so the result…

Ethan Hunt
- 97
- 5
0
votes
2 answers
Differences between all possible pairs of rows for all columns within each level of factor
I want to build all possible pairs of rows in a dataframe within each level of a categorical variable name and then make the differences of these rows within each level of name for all non-factor variables: row 1 - row 2, row 1 - row 3,…

Julien
- 1,613
- 1
- 10
- 26
0
votes
1 answer
How would I find all combinations/permutations with order mattering in R?
Hello and thanks for looking. I'm not exactly sure how to ask this question - let me show you an example and what I'm hoping to return.
example <- c(1, 2, 3, 4, 5, 6)
example_combos <- combn(example, 4)
1) How would I adapt combn() to just give me…

min7b5_b9_b11_b13
- 147
- 1
- 1
- 8
0
votes
3 answers
Looping in Dplyr
My question refers to looping in Dplyr. I'm trying to determine the mean, count number and variance for DV1 for each unique combination of independent variables (IV1:IV5). My data looks like this:
DV1 IV1 IV2 IV3 IV4 IV5
506.2 …

user1681537
- 59
- 1
- 7
0
votes
1 answer
Efficiently calculate a consensus set of members in R
I have a very large (millions of points) connected graph and many potential segmentation algorithms to determine group membership. Is there an existing implementation in sets or a similar R package for calculating a consensus set among possible…

bw4sz
- 2,237
- 2
- 29
- 53