I have a data frame that I would like to modify shown below
data <- data.frame(ID = c(1, 1, 1, 1, 1, 2, 2, 2, 3, 3), Assay = c("A", "B", "C", "D", "E", "A", "B", "C", "A", "B"), Genotype = c("AA", "BB", "CC", "DD", "EE", "AA", "BB", "CC", "AA", "BB"))
ID Assay Genotype
1 1 A AA
2 1 B BB
3 1 C CC
4 1 D DD
5 1 E EE
6 2 A AA
7 2 B BB
8 2 C CC
9 3 A AA
10 3 B BB
and I would like to take the Assay column and change that to the columns, where each ID is a row and then the genotype for each Assay, respectively. if there was no genotype for that Assay, then fill with NA values.
output <- data.frame(ID = c(1,2,3), A = c("AA", "AA", "AA"), B = c("BB", "BB", "BB"), C = c("CC", "CC", "NA"), D = c("DD", "NA", "NA"), E = c("EE", "NA", "NA"))
ID A B C D E
1 1 AA BB CC DD EE
2 2 AA BB CC NA NA
3 3 AA BB NA NA NA