I need one of my columns to be set as row name, accounting for duplicates, and the other columns should be separated by unique values into new columns assuming binary values if they are related to the row name.
Example:
ORIGINAL DATAFRAME
df <- data.frame(module = c("M1","M1","M1","M1","M1","M2"),
GO = c("inflama","inflama","ciclo","inflama","ciclo","sinapse"),
gene = c("PPARG","RELA","RELA","IRF5","ACKR1","GATA3"))
> df
module GO gene
1 M1 inflama PPARG
2 M1 inflama RELA
3 M1 ciclo RELA
4 M1 inflama IRF5
5 M1 ciclo ACKR1
6 M2 sinapse GATA3
FINAL DATAFRAME
df2 <- data.frame(gene = c("PPARG","RELA","IRF5","ACKR1","GATA3"),
M1 = c(1,1,1,1,0),
M2 = c(0,0,0,0,1),
inflama = c(1,1,1,0,0),
ciclo = c(0,1,0,1,0), sinapse = c(0,0,0,0,1))
> df2
gene M1 M2 inflama ciclo sinapse
1 PPARG 1 0 1 0 0
2 RELA 1 0 1 1 0
3 IRF5 1 0 1 0 0
4 ACKR1 1 0 0 1 0
5 GATA3 0 1 0 0 1
Thank you in advance for your help!