0

I would like to display combinations with non-zero frequency in a table after using filter in R.

Any help will be greatly appreciated. Thanks.

 library(tidyverse)
library(tidytext)
library(gtools)
library(magicfor) 
df = as.data.frame(rbind(c(1,0830,1,3,5), c(2,0845,3,4,5), c(3,0900,2,4,6), c(4,0915,1,3,6), c(5,0930,2,4,5)))
colnames(df) = c("draw","time","num1","num2","num3")
x<-c(1,2,3,4,5,6)
#One number
one_numb <- combn(x, 1, simplify = FALSE)
result <- list()
for(i in 1:length(one_numb)) {
result<-filter(df,(df$num1==one_numb[[i]][1] | df$num2==one_numb[[i]][1]  | df$num3==one_numb[[i]][1]   )) 
if (nrow(result)!= 0){
cat(sprintf("\"%.0f\" \"%.0f\"\n", one_numb[i], nrow(result)))
}
}

x<-c(1,2,3,4,5,6)
#Two numbers
two_numb <- combn(x, 2, simplify = FALSE)
result <- list()
for(i in 1:length(two_numb)) {
result<-filter(df,(df$num1==two_numb[[i]][1] | df$num2==two_numb[[i]][1]  
| df$num3==two_numb[[i]][1])
&(df$num1==two_numb[[i]][2] | df$num2==two_numb[[i]][2]  
| df$num3==two_numb[[i]][2] ) )
if (nrow(result)!= 0){
cat(sprintf("\"%.0f\" \"%.0f\"\n", two_numb[i], nrow(result)))
}
}
  • Please see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example on how to ask reproducible questions. The reason you haven't received any replies in a week is because nobody understands what output you need. – hmhensen Dec 21 '18 at 17:47
  • With cat(sprintf("\"%.0f\" \"%.0f\"\n", one_numb[i], nrow(result))) i got the combinations with frequency but with cat(sprintf("\"%.0f\" \"%.0f\"\n", two_numb[i], nrow(result)) i got error – Diyashvir Babajee Dec 22 '18 at 13:35

0 Answers0