I have a dataframe with gene names and miRNA interaction information. The dataframe looks like below:
df:
Gene miRNA
ACP1 hsa-let-7a-5p
AGO4 hsa-let-7a-5p
AMMECR1 hsa-let-7a-5p
ATM hsa-miR-100-5p
BMPR2 hsa-miR-100-5p
AGO1 hsa-miR-107
AGO2 hsa-miR-107
AGO3 hsa-miR-107
Using the above information which is gene-miRNA interaction information, I wanted to create a matrix. If there is interaction I would like to assign 1 if not 0. The matrix should look like below:
hsa-let-7a-5p hsa-miR-100-5p hsa-miR-107
ACP1 1 0 0
AGO4 1 0 0
AMMECR1 1 0 0
ATM 0 1 0
BMPR2 0 1 0
AGO1 0 0 1
AGO2 0 0 1
AGO3 0 0 1
I tried using xtabs
for this. Couldn't use it correctly.
xtabs(c(1L, 0L)[miRNA] ~ ., data=df)
Result looks like below:
Gene
ACP1 AGO1 AGO2 AGO3 AGO4 AMMECR1 ATM BMPR2
1 0 0 0 1 1 0 0
Any help is appreciated. thanq.