Questions tagged [combn]

121 questions
0
votes
1 answer

combn dataframe R for 1 variable only

I have a data.frame with the following structure: x1 x2 x3 x4 x5 x6 y n y n n y n n y n n y y y y y y n I want to make combinations combn() but using only for only 1 of the variable, I mean, gettingthis result: x1 x2 x1 x3 x1…
Ochetski
  • 105
  • 1
  • 13
0
votes
3 answers

Selecting combination with a fixed column in R

I have a data frame which looks like this aa bb -------- a 1 a 2 a 3 b 4 b 5 b 1 I want above data frame to have a pair of elements picked from 'bb' and look like the below frame aa bb …
user2575429
  • 111
  • 2
  • 3
  • 8
0
votes
1 answer

pairwise subtraction in a dataf rame with groups in different lengths

I have a data frame in 18528 rows and 3 columns like below: Sample Target Value 100 A 21.5 100 A 20.5 100 B 19.5 100 B 19.75 100 B 18.15 100 B 21.95 200 A 21.1 200 A…
Lili
  • 75
  • 7
0
votes
2 answers

How to convert a 'by' [list] output into a dataframe

data= data.frame(col1=c('m1','m1','m1','m2','m2', 'm2','m3', 'm3'), class=c('a','b','c','a','b','c', 'a', 'b'))I have a data.frame with 2 columns, the 1st column is a list of models, the 2nd column a list of model attributes. I need to show…
LuluPor
  • 165
  • 1
  • 11
0
votes
1 answer

Generate binary matrix of all nCm up to certain m with ncol=n

Wondering if there's a faster way to achieve the following: I have a vector of max. length long1 which is all zeros. How do I generate a matrix of all possible combinations of ones in certain positions up to and including the maximum max1s. The…
dardisco
  • 5,086
  • 2
  • 39
  • 54
0
votes
2 answers

generating a matrix with all possibilities in matlab

is there a simple command to do this: M = 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 i found this http://www.mathworks.co.kr/matlabcentral/fileexchange/7147-combn--4-3- but this isn't yet a thing in matlab tried M =…
jabk
  • 1,388
  • 4
  • 25
  • 43
-1
votes
1 answer

Combination with conditions in R

how to make a combination of letters label=c("A","B","C","D","E") into a dataframe with 4 group (G1, G2, G3, G4) as follows k2=data.frame(G1=c("AB","AC","AD","AE","BC","BD","BE","CD","CE","DE"), G2=c("C","B","B","B","A","A","A","A","A","A"), …
Michele
  • 29
  • 1
-1
votes
2 answers

All combinations of summing a vector of numbers together

Given I have the vector and a target number target.mountain <- 10 Roll_dice <- sample(1:6, 4, replace=TRUE) With Roll_dice producing [1] 6, 5, 3, 2 as an example How can I produce a list of all numbers in Roll_dice with all the ways of adding them…
-1
votes
2 answers

Creating a Basic R Dice Rolling Function to Sum Dice Values

I'm trying to write a function that combines up to 4 (fair 6 sided) dice rolls to create a specific value (named 'target.mountain') as many times as possible given the numbers shown on the dice. Then return these values along with any that aren't…
-1
votes
3 answers

Number of combs returned by combn reduced by some combs in R

I am trying to figure out how to reckon the number of combinations returned by combn function after exclusion of some selected combinations. Let's say, we have a vector c("var1","var2","var3","var4","var5") and I want to get all combinations of the…
New2coding
  • 715
  • 11
  • 23
-1
votes
1 answer

Create all vector combinations summing up to a specific number in R

I am trying to create a matrix with two combinations of the same vector that sum up to 2300. I am using thecombnfunction in R, see the code below: vector <- 400:1900 combinations <- combn(vector, 2, function(x) subset(x,…
Gion Mors
  • 313
  • 1
  • 3
  • 20
-1
votes
1 answer

R: How to apply median to combn output?

I have a dataframe: df1 vec1 vec2 vec3 vec4 vec5 0 10 5 12 5 10 20 13 1 7 20 30 28 13 16 And I perform combn() on it: x = combn( df1[,1:4] , 3 ) Which returns a matrix like this: x V1 …
James H
  • 159
  • 1
  • 8
-2
votes
1 answer

is there a R code for group_by and combinations

Am kindly looking for R code that can calculate the combinations with 2, of the total in each group. library(dplyr) id<-c(1,1,1,1,2,2,2,2,3,3,3,3) sex<-c(1,1,1,1,1,1,1,1,1,1,1,1) ds<-data.frame(id,sex) out1<-ds %>% group_by(id) %>%…
Sam Mwenda
  • 150
  • 8
-2
votes
1 answer

Why doesn't combn() using paste0 as the FUN give me the expected result (r)

I'm trying to create a list of combinations of strings using combn() with paste0 as the function, but all I get back is the matrix of combinations. What am I doing wrong? Example: combn(LETTERS[1:5],3, FUN=paste0) Gives me: [,1] [,2] [,3] [,4]…
iod
  • 7,412
  • 2
  • 17
  • 36
-3
votes
1 answer

Finding all unique combinations of 1:n numbers without packages

I need to create a function that provides me with all possible combinations of 1:n numbers. The argument of the function being n. I need to do this without using the combn function or any other pre-installed function within R. This picture above…
aa710
  • 69
  • 8
1 2 3
8
9