Hi there! I'm looking for a better way of getting the following code working -- can you help? Instead of having to type in: binarymissing(y ~ x1 + x2,data=mydata,na.action=na.keep) as my function call, I would prefer not having to type in na.action=na.keep each time as this will always be the same. The function na.keep is simply: na.keep <- function(X){X} The first few lines of the function binarymissing are: binarymissing<- function (formula, surrogates=NULL, data = sys.parent(), weights,na.action) { mf <- match.call() mf[[1]] <- as.name("model.frame") mf <- eval(mf, sys.frame(sys.parent())) Y <- model.extract(mf,response) Terms <- attr(mf,"terms") X <- model.matrix(Terms,mf) ... } I've tried a few different things that haven't worked: for example if I put na.action=na.keep on the first line of function as my default, the match.call line doesn't pick up the na.action value for some reason. Then when I use model.matrix it strips out all my missing values (i.e. na.action=na.omit not na.keep) which is not what I want! Hopefully I have made this problem clear enough to you... I'd really appreciate your help! Cheers, Rachel -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 8 Sep 2000, Rachel Merriman wrote:> Hi there! > I'm looking for a better way of getting the following code working -- > can you help? Instead of having to type in: > > binarymissing(y ~ x1 + x2,data=mydata,na.action=na.keep) > > as my function call, I would prefer not having to type in > na.action=na.keep each time as this will always be the same.options(na.action=na.keep) will set the global default na.action. Alternatively add the line if(is.null(mf$na.action)) mf$na.action=as.name("na.keep") after mf<-match.call() [or more generally if(is.null(mf$na.action)) mf$na.action==formals(binarymissing)$na.action which will fill in the actual default value] The reason that the obvious approach doesn't work is that match.call() returns the call that was actually typed, which has no na.action argument. This is then turned into a model.frame call with no na.action argument, which means that the default for model.frame, ie getOption("na.action"), is used. It's not completely clear whether this is a bug. One interesting question is whether we should have an option to match.call() that fills in defaults by looking at formals(call[[1]]). -thomas Thomas Lumley Assistant Professor, Biostatistics University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._