I have a dataset (DF) that looks like what I have below:
ID DOB Age Outcome
1 1/01/80 18 1
1 1/01/80 18 0
2 1/02/81 17 1
2 1/02/81 17 0
3 1/03/70 28 1
I want to change my database to wide format, so that I have one row per ID. However, given that DOB and Age are the same for each ID, I want these variables to be a single column in the new database and simply have multiple columns for the Outcome variable, as below:
ID DOB Age Outcome.1 Outcome.2
1 1/01/80 18 1 0
2 1/02/81 17 1 0
3 1/03/70 28 1 NA
I have tried using tidyr and reshape, but I can't seem to get the database into this format. For example when I use the code:
spread(DF, key=ID, value = Outcome)
I get an error that indicates that I have duplicate identifiers for rows. Is there a way to get the database into the format I would like?
Thanks.