Hi All,
I have an interesting data set that stores observations at what I am going to call "Event level" i.e. for one patient I have data that looks like this:
Subject..........Event..........Start Date..........End Date
1 ..................A ...............12/06/2014 ........25/12/2014
1 ..................B ...............26/08/2014 ........03/02/2015
1 ..................C ...............18/11/2014 ........30/04/2015
1 ..................D ...............08/03/2014 ........15/08/2015
I want to transform this data into what I am going to call "Subject level" data i.e. all this event information in one row/observation like below:
Subject..........Event 1..........Event 1 (duration)..........Event 2..........Event 2 (duration)..........Event 3..........Event 3 (duration) etc....
1................... A only.......... 75 days........................ A & B ...........84 days .......................A & B & C .....37 days................etc...
But obviously I am going to have different combinations of events and dates per subject so the aim is to write some generalisable or all-encompassing code. I can manipulate the dates into "days since" variables to make them easier to use, but I've been racking my brain for days as to how I may construct a loop or several nested loops to reshape my data.
Any ideas or advice would be greatly appreciated.
Thanks,
Rob.
I have an interesting data set that stores observations at what I am going to call "Event level" i.e. for one patient I have data that looks like this:
Subject..........Event..........Start Date..........End Date
1 ..................A ...............12/06/2014 ........25/12/2014
1 ..................B ...............26/08/2014 ........03/02/2015
1 ..................C ...............18/11/2014 ........30/04/2015
1 ..................D ...............08/03/2014 ........15/08/2015
I want to transform this data into what I am going to call "Subject level" data i.e. all this event information in one row/observation like below:
Subject..........Event 1..........Event 1 (duration)..........Event 2..........Event 2 (duration)..........Event 3..........Event 3 (duration) etc....
1................... A only.......... 75 days........................ A & B ...........84 days .......................A & B & C .....37 days................etc...
But obviously I am going to have different combinations of events and dates per subject so the aim is to write some generalisable or all-encompassing code. I can manipulate the dates into "days since" variables to make them easier to use, but I've been racking my brain for days as to how I may construct a loop or several nested loops to reshape my data.
Any ideas or advice would be greatly appreciated.
Thanks,
Rob.
Comment