I have a list of files that contain specific genes, and I want to create a binary relation matrix in R that shows the presence of each gene in each file.
For example, here are my files aaa
, bbb
, ccc
, and ddd
and the genes associated to them.
aaa=c("HERC1")
bbb=c("MYO9A", "PKHD1L1", "PQLC2", "SLC7A2")
ccc=c("HERC1")
ddd=c("MACC1","PKHD1L1")
I would like to know which command I could use in R to generate a binary relation table like the one in the following image:
where the value 1 means association, and the value 0 means non-association.
How can I do this operation in R?
I tried to use table(aaa,bbb,ccc,ddd)
but it did not work. R said:
Error in table(aaa, bbb, ccc, ddd) : all arguments must have the same length
EDIT: Thanks @akrun for your useful reply! I'll take advantage of this question to ask help for another issue, that I'm sure you guys can handle very quickly. For the second part of my analysis, I need to generate another table that where, for each pair of genes, I assign the value 1 if both of them present in the specific file, and 0 other wise. Following the example that I gave earlier, this new table should look like the following one (I transpose it for clarify):
Does anybody know a quick way to obtain this new bigenic table in R, starting from the commands you guys already provided to me? Thanks!