开发者

R script question - is.na telling me the condition has length > 1

In my r script, I do perform an nls to get a fit value:

fit <- nls(...)

and then after that, I test if the nls succeeded by doing this:

if(is.na(fit)) {
  print("succeeded")
}

but I get warnings:

the condition has length > 1 and only the first element will be used

am I doing this wrong? if so, what should I do? if not, how do I remove the warning? thanks!开发者_高级运维


nls induces an error if the fitting failed. So, is.null after try(nls(...)) is the correct way.

here is a piece of code I used when using nls fit for uncertain data:

fit <- NULL
while (TRUE) {
    start <- list(...) # try somewhat randomized initial parameter
    try(fit <- nls(..., start = start)) # performe nls
    if (!is.null(fit)) break;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜