s-news
[Top] [All Lists]

Combining two datetime columns in the same data frame

To: <s-news@lists.biostat.wustl.edu>
Subject: Combining two datetime columns in the same data frame
From: "El Imam Hanan Attia Rizk" <hanan.elimam@umontreal.ca>
Date: Fri, 14 Sep 2007 18:19:11 -0400
Thread-index: Acf3HUasYzPzSzOaSEKD9XHZGWnXVQ==
Thread-topic: Combining two datetime columns in the same data frame
Dear S plus users,

 

I am A PhD student and just started working with Splus Version7. At the moment 
I'm still preparing my datasheet, in which I have one particular issue that I 
do not know how to solve, I would really appreciate if any of you have the 
chance to give me some suggestions.

The data set I'm analyzing consists of many tables that I would like to merge 
them in one table containing the entire variables.

One of that tables (drug.frame) contains two timedate columns, starting the 
drug (on) and stop drug (off). 

 drug.frame

ID           on         off        drug1   drug2

1       1950-01-01    1950-09-30    1        0

1       1950-10-01    1951-05-30    0        1

2       1960-01-01    1960-09-29    1        0

2       1960-09-30    1962-10-01    0        1

3

3

Other tables like (cell.frame) containing only one timedate column.

 cell.frame

ID       celldate      obser1        obser2

1       1950-05-01       x             y

2       1960-05-01       x             y

 

I would like to combine all the info through a continuous date time for each ID 

So first I want to stack both on and off in the drug.frame into one column 
(on/off) then merge it with the cellldate column in the cell.frame for each ID 
as the following

 

ID    on/off/celldate            drug1      drug2     obser1       observ2  

1         1950-01-01(on)       1           0                       

    1950-05-01(celldate)                      x               y    

    1950-09-30(off)      1           0                

 1

 

 2

 

I tried to stack the time on and time off in the same column using the 
following code,

 bd.stack(drug.frame[1:6,], c("on", "OFF"),

          replicate="ID",

          stack.column.name="on/off/celldate",

          group.column.name="STACK.gp")

The result was like the following

 

 ID  on/off/celldate   STACK.gp

  1    1950-01-01       on

  1    1950-10-01       on

  2    1960-01-01       on

  2    1960-09-30       on

 

1   1950-09-30        off

1   1951-05-30        off

2   1960-01-01        off

2   1962-10-01        off

But that is different than what I want, could some one help me do that issue.

 

Best regards, 

 
Hanan Elimam
Ph.D student, Pharmaceutical Sciences
Université de Montréal
Faculté de pharmacie
Pavillon Jean-Coutu, bureau 3173
2940 Chemin de la polytechnique
Montréal, H3T 1J4
 
tél.:  514-343-6111, poste 0388
FAX: 514-343-7073

<Prev in Thread] Current Thread [Next in Thread>
  • Combining two datetime columns in the same data frame, El Imam Hanan Attia Rizk <=