I have data that looks something like:
patientid <- c(100,101,101,101,102,102)
weight <- c(1,1,2,3,1,2)
height <- c(0,6,0,0,0,1)
bmi <- c(0,5,0,0,0,1)
I want to group patient id so that there is only 1 patient per row in the dataframe.
Then put the other rows as additional columns (named by adding a number on the end). So the dataframe would be patientid, weight1, height1, bmi1, weight2, height2, bmi2, etc. The number of columns would correspond to how many repeated patient ids there were.
I assume group_by and spread are the key functions but I can't figure it out. In this example the row with patient id 101 would just have values in columns height1, bmi1 and weight1, patient 101 would have values in weight1, height1, bmi1, weight2, height2, bmi2, weight3, height3, bmi3 and patient 102 would have values in weight1, height1, bmi1, weight2, height2, bmi2.