Hi Justin, As already noted, you want to compare two values in your "if" statement. I think you may want to do it like this:
my_fun<-function(A,b) { for(j in 1:3) { x<-A; while((sum(x[j,])==1)) { x<-x%*%x; print(x); if(b%*%x[,j]==b[j]) break; } } } Jim Justin USHIZE RUTIKANGA wrote: >> Dear All, >> >> I am trying to determine the liming state probability . >> my_fun<-function(A,b){ >> for (j in 1:3){ >> x<-A; >> while ((sum(x[j,]) ==1) ) >> { >> x <- x%*%x; >> print (x); >> if ( b%*%x==b) >> { >> break; >> }}} >> } >> A<-rbind(c(.5,.3,.2), c(.3,.3,.4),c(.1,.5,.4)) >> b <- matrix(data=c(1,0,0), nrow=1, ncol=3, byrow=FALSE) >> my_fun(A,b) >> >> I got the following warning >> 1: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> 2: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> 3: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> 4: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> 5: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> 6: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> 7: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> 8: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> 9: In if (b %*% x == b) { : >> the condition has length > 1 and only the first element will be used >> your help will be appreciate >> ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.