[R] error statement: missing value where TRUE/FALSE needed

jim holtman jholtman at gmail.com
Tue Mar 24 01:30:09 CET 2009

I would assume the expression in the 'if' is giving an NA as a result:

> if (NA) 1 else 2
Error in if (NA) 1 else 2 : missing value where TRUE/FALSE needed

On Mon, Mar 23, 2009 at 10:38 AM, Michael Curran <mpc46 at cam.ac.uk> wrote:
> Hi list,
> I want to try Gibbs sampling as a method of estimating a markov-switching
> model of a mean-deviating, pth-order autoregressive process with time
> varying transition probabilities via R and am using a code originally
> written by another person; I attach the useful pdf document explaining the
> code. When I run the code, I get an error message:
> Error in if (r < vQ[i]) { : missing value where TRUE/FALSE needed
> I am using R.2.6.0 on Windows XP. Can anyone tell me what the error message
> means?
> The specific line in the code is:
> if (r<vQ[i]){ vS[i]=0 } else vS[i]=1
> The code is available at: http://www.michael-curran.com/gibbs.html
> and the two data sets are available at:
> http://www.geocities.jp/atsmatsumoto/ci.txt
> and
> http://www.geocities.jp/atsmatsumoto/callrate.txt
> Note: I saved the first data set as ci.txt and the second as boj.txt and so
> these are the file names that the code loads. If anyone uses the code and
> the data and manages to get it to work, I would gratefully appreciate if
> they could tell me what adjustments they made to the code in order to do so.
> Kind regards,
> Michael
> --
> Michael Curran
> Candidate for the MPhil in Economics
> Cambridge University
> http://www.michael-curran.com/
> ______________________________________________
> R-help at 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.

Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

More information about the R-help mailing list