john james
2010-May-25 09:06 UTC
[R] Selecting Monotone pattern of missingness from a dataframe
Dear R- users,
Pls help me with the following problem. I have a dataset that loooks like the
following:
jh<-data.frame(
'id'=seq(1,10,1),
'time0'=c(8,5,8,8,9,NA,NA,2,4,5),
'time4'=c(NA,NA,9,8,NA,2,3,2,4,5),
'time8'=c(NA,2,8,NA,5,NA,2,3,NA,4),
'sex'=c('m','f','m','m','f','f','f','m','f','m'),
'trt'=c('P','T','P','P','T','P','T','P','P','T')
)
I want to re-order the data frame so that the pattern of missing values is
monotone and select only monotone patterns, i.e a subset of 'jh' as
follows
orderjh<-data.frame(
'id'=c(3,8,10,4,9,1),
'time0'=c(8,2,5,8,4,8),
'time4'=c(9,2,5,8,4,NA),
'time8'=c(8,3,4,NA,NA,NA),
'sex'=c('m','m','m','m','f','m'),
'trt'=c('P','P','T','P','P','P')
)
Any help will be appreciated. Thanks.
John
[[alternative HTML version deleted]]