Получить первые n комбинаций на основе нескольких столбцов, в которых комбинация определяется как большинство вхождений. Скажем, мне нужны 3 первых вхождения из моих входных данных:
Набор входных данных:
Product <- c("XX","XX","XX","ZZ","YY","ZZ","YY","ZZ","YY","YY","XX",
"ZZ","XX","ZZ","ZZ","YY","YY","XX","YY","ZZ","ZZ","ZZ","ZZ","YY",
"XX","ZZ","ZZ","ZZ","YY","XX")
Grade <- c("A","B","A","C","B","A","C","B","C","A","B", "C","B","A","A","C","A","B","C","A",
"C", "C","A","B","A","A","A","B","C","A")
Pass <- c(1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,1,1)
Sample_Dataset <- data.frame(Product, Grade, Pass) #input Dataset
Желаемый результат:
> Top3_Combinations
Product Grade Pass Occurences
1 ZZ A 0 6
2 YY C 1 5
3 XX A 1 4
Также включите комбинации, которые имеют Связи, например, если есть другая комбинация, которая имеет 4 вхождения, также включает ее.