Skip to content
Prev 255682 / 398506 Next

How do I modify uniroot function to return .0001 if error ?

eric <ericstrom <at> aol.com> writes:
Do not modify uniroot(). Use 'try' or 'tryCatch', for example

    	e <- try( d <- uniroot(k, c(.001, 250), tol=.05), silent = TRUE )
	if (class(e) == "try-error") {
		return(0.0001)
	} else {
		return(d$root)	
	}

--Hans Werner