Hello,
Maybe there are simpler ways of doing it, but try the following.
sp <- lapply(split(dat, dat$id), function(.s){
i <- min(which(.s$stat == 0), which(.s$g == 1))
.s$d <- .s$stop[i]
.s[-1][row(.s[-1]) >= i] <- NA
.s
})
dat3 <- do.call(rbind, sp)
rownames(dat3) <- seq_len(
On Sep 17, 2012, at 11:32 AM, john james wrote:
> Dear R users,
>
> I have the following problems. My dataset (dat) is as follows:
>
> a <- c(1,2,3)
> id <- rep(a, c(3,2,3))
> stat <- c(1,1,0,1,0,1,1,1)
> g <- c(0,0,0,0,0,0,1,0)
> stop <- c(1,2,4,2,4,1,1.5,3)
> dat <- data.frame(id,stat,g,st
2 matches
Mail list logo