[R] can predict ignore rows with insufficient info

Thomas W Blackwell tblackw at umich.edu
Tue Sep 16 22:31:29 CEST 2003


Peter  -

Error !!
I forgot a "not" in the third line inside the function supported().
And, my mail editor doesn't balance parentheses, so I don't guarantee
that my code is even syntatically correct.

Corrected and re-named version of function:

unsupported <- function(i,y,d)  {
   result <- rep(F, dim(d)[1])      # default return value when
   if (is.factor(d[[i]]))           #  d[[i]] is not a factor.
     result <- !(d[[i]] %in% unique(d[[i]][ !is.na(d[[y]]) ]))
   result  }

tmp.1 <- lapply(seq(along=const), unsupported, "days", const)
tmp.2 <- matrix(unlist(tmp.1[ names(const) != "days" ]), nrow=dim(const)[1])
tmp.3 <- as.logical(as.vector(tmp.2 %*% rep(1, dim(tmp.2)[2])))

x <- predict(g, const[ is.na(const$days) & !tmp.3, ])

-  tom blackwell  -  u michigan medical school  -  ann arbor  -




More information about the R-help mailing list