[R] Creating dropout time from longitudinal data with missing data

2010-05-31 Thread john james
Dear R users,   Please assist me with the following problem. I have a dataset that looks like the following:   dat-data.frame(   'id'=rep(c(1,2,3),each=3),   'time'=rep(c(1,2,3),3),   'y'= c(2,2,NA,2,NA,NA,2,5,7) )   I wish to create a variable for dropout time in dataframe 'dat' such that the

Re: [R] Creating dropout time from longitudinal data with missing data

2010-05-31 Thread Dennis Murphy
Hi: Here are a few ways: (1) ave(): transform(dat, dropout.time = ave(y, id, FUN = function(x) sum(!is.na(x (2) same as (1) without the transform() statement: dat$dropout.time - ave(y, id, FUN = function(x) sum(!is.na(x))) dat (3) ddply() in the plyr package: library(plyr) snisna -