omit.action.R 826 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
na.omit.procmod.frame=function (object, ...)
{
  n <- length(object)
  omit <- logical(nrow(object))
  vars <- seq_len(n)
  for (j in vars) {
    x <- object[[j]]
    omit= omit | rowSums(is.na(x))>0
  }
  xx <- object[!omit, , drop = FALSE]
  if (any(omit > 0L)) {
    temp <- setNames(seq(omit)[omit], attr(object, "row.names")[omit])
    attr(temp, "class") <- "omit"
    attr(xx, "na.action") <- temp
  }

  return(xx)
}

#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
na.exclude.procmod.frame=function(object, ...) {
  xx = na.omit.procmod.frame(object, ...)
  na.action = attr(xx, "na.action")
  if (! is.null(na.action)) {
    class(na.action)="exclude"
    attr(xx, "na.action")=na.action
  }

  return(xx)
}