# Computing combinations [closed]

I am having a problem in getting all the combinations from my dataset. I need your suggestions and guidance in doing so.

I have a file, whose first column contains the regions and other file five column represents if a binding event takes place or not.

Region  TF1 TF2 TF3 TF4 TF5
Reg1    8   0   4   9   11
Reg2    2   0   0   4   0
Reg3    0   8   9   0   3
Reg4    6   82  8   0   4


Here the most prevalent combination is of TF1,TF3,TF4, TF5 & TF1, TF2, TF3, TF5. .

I have a file of 1700 regions (rows) and 25 binding events(columns).

How can I get near to my desired result with some associated score for each combination.

Thank you.

• This question appears to be off-topic because it is about programming. – whuber Feb 27 '14 at 21:31

The data:

dat <- read.table(text="Region  TF1 TF2 TF3 TF4 TF5
Reg1    8   0   4   9   11
Reg2    2   0   0   4   0
Reg3    0   8   9   0   3
Reg4    6   82  8   0   4", header = TRUE)


The following commands can be used to obtain the frequencies of the unique combinations of bindings:

tab <- table(apply(dat[ , -1] != 0, 1, paste, collapse = "."))

as.data.frame(setNames(tab, lapply(names(tab), function(x)
paste(names(dat)[-1][as.logical(strsplit(x, "\\.")[[1]])], collapse = ", "))))


The output:

                Var1 Freq
1      TF2, TF3, TF5    1
2           TF1, TF4    1
3 TF1, TF3, TF4, TF5    1
4 TF1, TF2, TF3, TF5    1

• Is it possible to associate the combination with any sort of scoring or p-value or z-score? – Angelo Nov 26 '12 at 13:37
• @Angelo Yes, the combinations could be associated with any other information. You should provide an example. – Sven Hohenstein Nov 26 '12 at 13:39
• Sorry, I figured it out. Secondly how can I direct the output to a file? Thank you in advance – Angelo Nov 26 '12 at 16:09
• I did store the result in a variable for example in "result" Now how can I transfer the data stored in this variable to an excel file :( – Angelo Nov 26 '12 at 16:11
• @Angelo write.csv2(result, row.names = FALSE, file = "filename.csv") – Sven Hohenstein Nov 26 '12 at 16:14