I am dealing with a dataset which is in a long format as shown below.
id Name FluidTotal
60718 Rocuronium 11.069175
07860 Rocuronium 5.967500
90389 Rocuronium 200.000000
01536 Rocuronium 78.311333
01536 Rocuronium 51.415600
28047 Rocuronium 72.944444
28047 Acid 1
28047 Acid 1
28047 Acid 1
28047 Acid 1
92323 Acid 1
92323 Void 100
01536 Void 25
60718 Void 70
60718 Void 40
What I am trying to do is transform this to a wide format like this below
Id Rocuronium Acid Void
60718 11.069175 - 110
07860 5.967500 - -
90389 200.000000 - -
01536 129.72693 - 25
28047 72.944444 4 -
92323 - 1 100
The first row is 60718 11.069175 - 110
, the cell value for Void
is 110
because the last two rows for id 60718
in the long format are 70
and 40
so when they are converted to wide format these two values are added.
Similarly the value of Rocuronium
for id 01536
in wide format is 129.72693
because rows 4 and 5 in the long format for this id 01536
are 78.311333
and 51.415600
I'd appreciate any assistance on accomplishing this transformation, thanks in advance..