Dear all, When I try to return some vectors from some functions within a function, it indicate an error," Error in rbind(ck1, ck2, ck3) : object 'ck1' not found", in one of the iterations and stop. Since I am not experienced in programming, can anyone give me a suggestion to inspect this error? The followings are the functions I created :
################### # functions in the convg # ################### check1 <- function(sumgt,beta1.0,gamma.0,sigma.0){ Â Â if (any(!is.finite(sumgt))){ Â Â Â Â Â Â count1 <- count1+1 Â Â Â Â Â Â return(c(count1,beta1.0,gamma.0,sigma.0)) Â Â } Â else {return(c(NaN,NaN,NaN,NaN))} Â } check2 <- function(v0,maxit,iter,beta1.0,gamma.0,sigma.0){ Â Â Â if (is.nan(sum(v0))==TRUE | any(!is.finite(v0)) | maxit == iter){ Â Â Â Â Â Â count1 <- count1+1 Â Â Â Â Â Â return(c(count1,beta1.0,gamma.0,sigma.0)) Â Â } Â Â else {return(c(NaN,NaN,NaN,NaN))} Â } check3 <- function(maxit,diff,error,beta1.0,gamma.0,sigma.0){ Â Â Â if (diff < error) { Â Â Â Â Â Â return(c(count,beta1.0,gamma.0,sigma.0))Â Â Â Â Â Â Â Â Â Â Â Â } Â Â else {return(c(NaN,NaN,NaN,NaN))}Â Â Â Â } convg <- function(count1,count,sub,rep,n,data1,beta1.0,gamma.0,sigma.0,v0,L,diff,error,iter,maxit){ Â Â while(diff > error && maxit < iter && max(abs(c(beta1.0,gamma.0,sigma.0))) < 10 && is.nan(sum(v0))==FALSE && any(is.finite(v0))){ Â Â Â Â Â Â Â Â Â Â : Â Â Â Â Â Â Â Â Â Â : Â ck1 <- check1(sumgt,beta1.0,gamma.0,sigma.0) Â Â Â Â Â Â Â Â Â Â : Â Â Â Â Â Â Â Â Â Â : Â ck2 <- check2(v0,maxit,iter,beta1.0,gamma.0,sigma.0) Â Â Â Â Â Â Â Â Â Â : Â Â Â Â Â Â Â Â Â Â : Â ck3 <- check3(maxit,diff,error,beta1.0,gamma.0,sigma.0) Â } return(rbind(ck1,ck2,ck3)) } Â Thank you so much Sincerely, Joe [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.