Questions tagged [combn]
121 questions
0
votes
1 answer
Generate as many data frames as permutation of columns
I would like to generate as many data frames as the number of permutation of my columns, given that one column as to remain unpermutated (keep the same index position in all generated data frames). Here is the main dataframe:
data1 <-…

Elixterra
- 281
- 1
- 3
- 11
0
votes
1 answer
Subset data.table based on all possible combinations of two or more variables
I want to subset a data.frame based on if some variables are all positive, all negative or some combination in between. For n variables this should lead to 2^n possible combinations.
I think combn can be used to achieve this but I'm struggling to do…

Gautam
- 2,597
- 1
- 28
- 51
0
votes
5 answers
Excluding certain combinations from combn function in R
I am trying to exclude all combinations generated by combn function that consists of "var4" and "var5". Here below is the code that does not work at the moment:
mod_headers <- c("var1", "var2", "var3", "var4", "var5", "var6")
f <- function(){
…

New2coding
- 715
- 11
- 23
0
votes
0 answers
How to remove correlated variables from GLM in R
I am trying to exclude correlated variables from GLModel. Firstly, I calculate correlation matrix. Afterwards, I would like to implement it into combn function in some way to exclude the variables (column headers) that are correlated. At this point…

New2coding
- 715
- 11
- 23
0
votes
2 answers
Counting appearances of combination of elements in R
I have a big client who purchases from me in a high frequency. I would like to know which combinations of products he often purchases together. For example, every time he buys product A he also buys product W. And the same happens for other…

Felipe Alvarenga
- 2,572
- 1
- 17
- 36
0
votes
1 answer
Formatting R combn output
As a short example, when running combn(1:5,2), I get a matrix of 2 rows and 10 columns.
I know I can convert the output matrix to a data frame, but is it possible (any option inside combn) to have the output readily in the form of a vertical data…

Andrew
- 926
- 2
- 17
- 24
0
votes
1 answer
How to create all the combinations in a vector using R
I have a vector of n observations. Now I need to create all the possible combinations with those n elements. For example, my vector is
a<-1:4
In my output, combinations should be…

789372u
- 77
- 1
- 8
0
votes
1 answer
Intersecting many pairs of integer vectors
I have a list of integer vectors:
set.seed(1)
l <- list(g1=as.integer(runif(10,1,100)),
g2=as.integer(runif(5,1,100)),
g3=as.integer(runif(5,1,100)),
g4=as.integer(runif(8,1,100)))
(in reality it's 1000's elements long…

dan
- 6,048
- 10
- 57
- 125
0
votes
0 answers
R logical combinations of between two groups
I am seeking some help regarding combinations in R.
Simplified, I have a group consisting of three individuals (I) and some markers (M) I am interested in studying. Each individual will either be positive or negative for each marker. Some markers…

student
- 11
- 2
0
votes
1 answer
Get unique combination (combn) by ID in R
I try to get unique combination by each ID, I keep get error, it doesn't expand ID.
ID <- c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,5,5,6,6,6,6)
var1 <- c("A","B","E","F","C","D","C","A","B","C","A","D","B","C",
…

BIN
- 781
- 2
- 10
- 24
0
votes
1 answer
Extract a specific combination from all possible combinations in R
Given the following vector of length n=10:
# [1] 0 0 0 0 0 1 0 0 1 0
vec <- c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L)
Suppose we want to apply the operator & to all possible combinations of the vector elements. That is:
res <- combn(n, 2,…

989
- 12,579
- 5
- 31
- 53
0
votes
0 answers
Error subscript out of bounds when using combn
I am trying to created an equally weighted portfolio with calculated returns. The code is as follows:
library(quantmod) # Quant Package
getSymbols("FB", src = "yahoo", from = as.Date("2015-08-01"), to = Sys.Date())
getSymbols("GOOG", src =…

Raza Akhtar
- 11
- 3
0
votes
1 answer
R: how can I reference the corresponding column between a combination of names within a dataframe?
I've managed to make different combinations of 2 from a set of data so that I get the pairs of names within the data set. I would like to have a function when I use mapply so that I can use each name in each pair to reference their corresponding…

Luke Zhang
- 343
- 1
- 4
- 14
0
votes
1 answer
pass a 2-parameter function to combn
I'm using the built in dataset "ChickWeight". For each name, weight, Time, Chick, Diet, my function is simply taking the difference between each pair of names, weight Time, weight Chick, weight Diet, Time Chick, Time Diet, Chick Diet. The function…

Luke Zhang
- 343
- 1
- 4
- 14
0
votes
2 answers
Create combinations within a split group in r
With the data frame below of Locations, Days, and Quantities, I'm searching for a solution to create combinations of quantities by Location across each Day. In production, these combinations may grow pretty large, so a data.table or plyr approach…

Brian
- 195
- 8