[R] Splitting survivor episodes

Thomas Lumley tlumley at u.washington.edu
Sat Mar 1 01:47:03 CET 2003


On Fri, 28 Feb 2003, Daniel A. Powers wrote:

> To R-list --
>
> Does anyone know of an R function that will create split-episode data from
> single spell event/duration data according to user-defined time intervals?
>
> Example: original data
>  t     d  x
> ------------
>  6     0  x1
>  5     1  x2
>
> Split using intervals [0,3) [3,infty) (or cutpoint at 3)
>
>  start end    event
>  _t0    _t     _d   _x  episode
>    0     3      0   x1   1
>    3     6      0   x1   2
>    0     3      0   x2   1
>    3     5      1   x2   2
>

No.

I do something like

   n<-nrow(data)
   data<-rbind(data,data)
   data$episode<-rep(c(1,2),each=n)
   data$start<-rep(c(0,CUT),each=n)
   data$end <- c(rep(CUT,n), data$t)

   ##drop episodes after death
   data<-subset(data, start<t )

   ## define event
   data$event <- with(data, ifelse(t<end, event, 0))

   ## tidy up end times
   data$end <- pmin(data$t, data$end)


	-thomas




More information about the R-help mailing list