s-news
[Top] [All Lists]

Re: first record per occasion

To: "'Pravin Jadhav'" <pravinj@gmail.com>, s-news@wubios.wustl.edu
Subject: Re: first record per occasion
From: "Austin, Matt" <maustin@amgen.com>
Date: Sun, 28 Nov 2004 22:44:39 -0800
The following gets the baseline value, but if two values were from the same
day and time (two observations from the same blood sample) then both would
be in the output dataset.  To remedy this, you could take the min or max --
whichever is correct scientifically in your data.

df <- read.table(file='c:/data_mirror/snews.dat', header=TRUE,
stringsAsFactors=FALSE)
df$visit <- timeDate(paste(df$DATE, df$TIME))
df$visitday <- as.integer(df$visit)

base.list <- by(df,
           list(df$ID, df$visitday),
           function(x){
             x[which(as.numeric(x$visit) - min(as.numeric(x$visit)) <
.Machine$double.eps),]
})

base.df <- do.call('rbind', base.list)
base.df[order(base.df$ID, base.df$visit), c('ID', 'DATE', 'TIME', 'OBS')]
  ID       DATE TIME OBS 
1  1 05/30/2000 7:00 100
5  1 06/28/2000 8:00 100
9  2 05/30/2000 7:00 101

--Matt

Matt Austin
Statistician

Amgen 
One Amgen Center Drive
M/S 24-2-C
Thousand Oaks CA 93021
(805) 447 - 7431


> -----Original Message-----
> From: s-news-owner@lists.biostat.wustl.edu
> [mailto:s-news-owner@lists.biostat.wustl.edu]On Behalf Of 
> Pravin Jadhav
> Sent: Sunday, November 28, 2004 20:8 PM
> To: s-news@wubios.wustl.edu
> Subject: [S] first record per occasion
> 
> 
> Hello,
> 
> I have repeated measures available for several individuals. There are
> about 2-4 occassions per individual identified by the date of their
> visit. Is there is any function that allows me to extract the first
> observation per visit (basically, baseline at each visit).
> 
> The only information available in the dataset is (1) ID# (2) DATE (3)
> TIME (4) OBS.
> 
> I have tried generating occassion number by finding unique date
> (?unique) but there are a few individuals visiting on the same date.
> So it didn't work.
> 
> Example:
> ID     DATE             TIME     OBS
> 1       05/30/2000     7:00       100
> 1       05/30/2000     9:00       101
> 1       05/30/2000     11:00     102
> 1       05/30/2000     13:00     103
> 1       06/28/2000     8:00       100
> 1       06/28/2000     10:00     101
> 1       06/28/2000     12:00     102
> 1       06/28/2000     15:00     103
> 2       05/30/2000     7:00       101
> 2       05/30/2000     9:00       101
> 2       05/30/2000     10:00     102
> 2       05/30/2000     12:00     103
> 
> I am interested in getting the following information
> ID     DATE             TIME     OBS
> 1       05/30/2000     7:00       100
> 1       06/28/2000     8:00       100
> 2       05/30/2000     7:00       101
> 
> Any commets are much appreciated.
> 
> Thanks.
> 
> Pravin
> -- 
> Pravin Jadhav
> Graduate Student
> Department of Pharmaceutics
> MCV/Virginia Commonwealth University
> DPE1/CDER/OCPB/Food and Drug Administration
> Phone: (301) 594-5652
> Fax: (301) 480-3212
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news
> 

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