[R] selecting monotone pattern of missing data from a dataframe with mixed pattern of missingness

From: john james <dntssa_at_yahoo.com>
Date: Mon, 31 May 2010 21:13:34 -0700 (PDT)

Dear R- User,

I have a dataset that looks like the following:

I was earlier furnished (from R-help) with the function below:

f <- function (x) {
    o <- do.call(order, c(list(rowSums(is.na(x))), lapply(x[,
        order(-sapply(x, function(x) sum(is.na(x))))], function(x) is.na(x))))
    xo <- x[o, , drop = FALSE]
    isNonterminalNA <- function(x) is.na(x) &
               rev(cummax(!is.na(rev(x))) > 0)
    good <- rep(TRUE, nrow(x))
    for (j in seq(along = x)) {
        good <- good & !isNonterminalNA(xo[, j, drop = TRUE])
    xo[good, , drop = FALSE]


The function works well when the measurement occassions are just 3. When the measurement occassion becomes 4, I observed that pattern X X X NA is exclude, which is also a monotone pattern. Please how do i adjust a function like this to work in all cases. i.e to select only monotone patterns:




Many thanks in advance

	[[alternative HTML version deleted]]


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 01 Jun 2010 - 05:25:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jun 2010 - 05:40:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive