s-news
[Top] [All Lists]

derive intervals a subject is taken the same dose

To: "'s-news@lists.biostat.wustl.edu'" <s-news@lists.biostat.wustl.edu>
Subject: derive intervals a subject is taken the same dose
From: "Stuyckens, Kim [PRDBE]" <KSTUYCK1@PRDBE.JNJ.COM>
Date: Wed, 21 Jun 2006 16:35:39 +0200

Dear S-News users,

I have a dataset which looks as follows containing thousands of rows:
ID      DOSE    DATE
1       0.25    01/01/2006
1       0.25    01/02/2006
1       0.50    01/03/2006
1       0.25    01/04/2006
1       0.25    01/05/2006
1       2.50    01/06/2006
1       2.50    01/07/2006
1       0.25    01/08/2006
2       2.50    01/09/2006
2       2.50    01/10/2006
2       2.50    01/11/2006
2       3.50    01/12/2006
2       2.50    01/13/2006
2       2.50    01/14/2006
2       2.00    01/15/2006
2       2.00    01/16/2006
2       4.00    01/17/2006
3       2.00    01/18/2006
3       2.50    01/19/2006
3       2.50    01/20/2006
3       2.00    01/21/2006
3       2.00    01/22/2006

a _data.frame(ID = c(1 ,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3),
                        DOSE= c(.25,.25,.5,0.25,0.25,2.5,2.5,0.25,  2.5,2.5,2.5,3.5,2.5,2.5,2,2,4,2,2.5,2.5,2,2),
                        DATE= timeDate(as.character(seq.dates("01/01/2006", by="days", length=22))) )

My problem is that I would like to find the dosing time intervals that a certain ID(subject in this case) takes the same dose. Mind that the same dose can return within the same ID at a later point in time.

The desired result looks as follows

ID      DOSE    STARTDATE       ENDDATE
1       0.25    01/01/2006      01/02/2006
1       0.50    01/03/2006      01/03/2006
1       0.25    01/04/2006      01/05/2006
1       2.50    01/06/2006      01/07/2006
1       0.25    01/08/2006      01/08/2006
2       2.50    01/09/2006      01/11/2006
2       3.50    01/12/2006      01/12/2006
2       2.50    01/13/2006      01/14/2006
2       2.00    01/15/2006      01/16/2006
2       4.00    01/17/2006      01/17/2006
3       2.00    01/18/2006      01/18/2006
3       2.50    01/19/2006      01/20/2006
3       2.00    01/21/2006      01/22/2006

I solved this problem until now with a loop to look for the moment when dose is changing, but I hope there is a more efficient way because the loop is taking to much time and gives memory problems  with the amount of data I have.

Any input or suggestions are very much appreciated

BTW I am using SPLUS 6.2 in a Windows environment

Thanks in advance,
Kind regards,
Kim

<Prev in Thread] Current Thread [Next in Thread>