Questions tagged [combn]

121 questions
2
votes
2 answers

Split a dataframe into all possible combinations of dataframes by 3 columns in R

I need to receive all possible dataframes from the split of an original dataframe into all possible combinations of 3 columns. And all dataframes must contain id column. I'm at a dead end and do not know how to save all possible dataframes so that…
iomedee
  • 381
  • 1
  • 14
2
votes
2 answers

combn on grouped DT returns error "n < m"

I have a data set with 31557 observations, and the variables Order.number and Materials. I'm trying to run this in R: First: DT <- data.table(Order.number=X$Order.number, Materials=X$Materials) setorder(DT, Order.number,…
M.A
  • 65
  • 1
  • 8
2
votes
0 answers

Creating Dataframes of all Possible Combinations without Repetition of Columns with cbind

I have 3 data frames that each look like this: head(New_Re) JPM.GBI.GLOBAL MSCI.WORLD.U MSCI.EM.U WORLD.DS.Market EMERGING.MARKETS.DS S.P.GSCI HFRI.FUND.WEIGHTED 2000-01-31 -0.23666947 -0.68583345 0.07151953 -0.5730685 …
El_1988
  • 339
  • 3
  • 13
2
votes
1 answer

R: combn pair of variables calculate the mean between them

I have a data frame of 20 variables, each variable has 2 observations. I have computed all the possible pairs of variables with combn, and now for each observation and each pair, I would like to compute the mean. 190 combinations are possible taking…
Anais
  • 79
  • 10
2
votes
1 answer

Get combinations of grouped data

Please show me the proper 'r' way. I have 5 locations. Every day each location will have 0 or 2 values. I want to get the possible combinations of locations by day. The code below works but I don't think it's very good. Is there a better way to…
2
votes
1 answer

Speed up Combn to ID matrix R

This little problem is the bottleneck of a big code which must be repeated at least thousands of times so the main issue here is the speed. I have a vector of numbers, for example: v <- c(1,3,5) I want to know all the combinations I can make with…
2
votes
1 answer

meaning of combn error: Error in FUN(X[[i]], ...) : n < m in R

Trying to create a pair of element but get the following error: Error in FUN(X[[i]], ...) : n < m The error appears after running the code: rslt <- lapply(split(my$symbol, my$character), combn, 2, simplify = F) Here my is my data frame and symbol…
2
votes
2 answers

Assign names to dataframes within a list based on combn

I have created a list of dataframes using alply (~500), in the manner; prevalence <- alply(combos, 2, prevalence.func) I'd like to assign new names to each data.frame based on the same combos, replacing the default numeric names…
danny_C_O_T_W
  • 228
  • 2
  • 8
2
votes
2 answers

combn-like task for combinations as elements in R

not sure if I chose a good title at all... Also I don't know if I use the right terminology, so maybe with the right search terms I would find a solution to this problem... I have a list of strings from which I want to have all sets of "exclusive"…
Ingo
  • 53
  • 6
2
votes
1 answer

Keep column names after calling function combn

After looking at another post about column names and combn function here consider the same data.frame. We make a combn with all 2 possible vectors: foo <- data.frame(x=1:5,y=4:8,z=10:14, w=8:4) all_comb <- combn(foo,2) Is there a way to keep column…
2
votes
2 answers

Set column names while calling a function

Consider we have a numeric data.frame foo and want to find the sum of each two columns: foo <- data.frame(x=1:5,y=4:8,z=10:14, w=8:4) bar <- combn(colnames(foo), 2, function(x) foo[,x[1]] + foo[,x[2]]) bar # [,1] [,2] [,3] [,4] [,5] [,6] #[1,] …
Ali
  • 9,440
  • 12
  • 62
  • 92
1
vote
2 answers

Using combn to make specific functions for grouped pair-wise, row-wise comparisons

This is a small section of a dataset I'm working on. dat2 <- read.table(text = " nodepair V1 V2 V3 V4 V5 V6 V7 V8 V9 ES 1 A1_A1 0 21 0 0 0 0 0 0 78 45 2 A2_A1 0 0 0 0 0 …
1
vote
1 answer

Generate random pairs of factors in dataframe using R

I have a character vector data frame and I would like to randomly generate pairs of names coming from this vector. My code gives the all combinations. But I want to generate all names should be paired with one time in random order; an item cannot be…
Lincy
  • 23
  • 4
1
vote
1 answer

Faster way to multiply combination of variables in a data frame

I would like someone to suggest a faster way complete the following steps: Using the variables in orig_df, generate unique combination of variables. Multiply the unique combination of variables from step 1 and cbind the new variables to…
On_an_island
  • 387
  • 3
  • 16
1
vote
2 answers

Combination with all data in group

I want to make 5 data into 3 groups with the condition that all data is in a group. Suppose the data I have (A, B, C, D, E). Then the possible combinations to be made into 3 groups are as follows.
Michele
  • 29
  • 1
1 2
3
8 9