Let's suppose we have the dataframe below:
df <- read.table(header=T, text=
'Patient_ID Gene Type
1 ATM 3
1 MEN1 1
2 BRCA1 3
2 RAD51C 2
2 BRCA2 2
3 CHEK2 1
4 MUTYH 1
4 BRCA2 3', stringsAsFactors=F)
How can I rearrange this dataframe to make it look like the following :
ID ATM MEN1 BRCA1 RAD51C CHEK2 MUTYH BRCA2
1 3 1
2 3 2 2
3 1
4 1 3
Please note that each row is now a unique case and the column Type
was used to provide the values for the new created columns.