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, Materials)
Then:
library(data.table)
ans <- DT[, as.data.table(do.call(rbind, combn(Materials, 2, simplify=FALSE))),
by=Order.number][,
.N, by=.(V1, V2)]
But I get the error in combn(Materials, 2, simplify = FALSE) : n < m
It works if I just use random generated table. So could it be something to do with the dataset I have?
EDIT: I tried with meaning of combn error, but getting "Error in do.call(rbind, function(x) if (length(x) > 1) { : second argument must be a list"
ans <- DT[, as.data.table(do.call(rbind, function(x)
if(length(x)>1) {
combn(Materials, 2, simplify=FALSE)
}
else x)),
by=Order.number][,
.N, by=.(V1, V2)]