I have a dataframe that looks like this:
'data.frame': 430 obs. of 8 variables:
$ date: chr "12 June 2020" "05 June 2020" "29 May 2020" "22 May 2020" ...
$ X1 : int 7 9 22 15 34 11 21 35 33 43 ...
$ X2 : int 22 16 31 40 49 15 11 13 41 50 ...
$ X3 : int 30 17 36 32 29 36 41 34 1 2 ...
$ X4 : int 48 29 8 45 21 9 6 6 18 8 ...
$ X5 : int 16 39 32 12 27 43 12 15 23 7 ...
$ num1: int 8 1 6 7 8 9 2 5 6 3 ...
$ num2: int 2 8 10 10 10 8 1 1 2 2 ...
I need to find the 10 most common pairs within num1 and num2; and the 10 most common pairs within X1, X2, X3, X4, X5.
For the first problem I have got
names(tail(sort(table(unlist(tapply(mydf$num1, mydf$num2, FUN=function(x) combn(unique(x), 2, paste, collapse="-"))))),10))
which produces the output
[1] "7-2" "7-4" "7-5" "8-3" "1-3" "3-1" "4-1" "3-2" "4-2" "1-2"
which works. But I can't transform the code to do the same for X1, X2, X3, X4, X5. I have tried the most obvious (to substitute mydf$num1 etc. to mydf$X1 etc), but I get all sorts of errors, I'm guessing because this time I'm trying to find pairs across 5 variables. Any suggestions as to how to do this would be most welcome.
=========
Edit: Not sure if this helps but this is what I mean:
In this dataset 13-34 is a pair and 41-23 is another. (There may be more, I just did it by looking at it - this is exactly what I am trying to avoid.) So I am trying to find which two numbers occur together and of these which are the most common pairs.