Try this:
foo <- function(x) {
data.frame(Id = unique(x$Id), rbind(range(x$time)), dose =
unique(x$dose))
}
t(sapply(split(as.data.frame(orig.data),
with(rle(orig.data[,'dose']), rep(seq_along(lengths),
lengths))),
foo))
On Wed, Mar 24, 2010 at 12:27 PM
Hi,
I have a data set in which the variable 'dose' is time-varying. Currently,
the data set is in a long format, with 1 row for each time unit of follow-up
for each individual "Id". It looks like this:
orig.data <- cbind(Id = c(rep(1,4), rep(2,5)), time = c(1:4, 1:5), dose =
c(1,1,1,0,1,0,1,1,0)
2 matches
Mail list logo