[R] missing value where TRUE/FALSE needed
jim holtman
jholtman at gmail.com
Sat Nov 8 02:58:48 CET 2008
It would be useful to learn how to use debug/browser. Here is the
state of the machine when the error occurs:
> test()
Error in if (vector1[i] == vector2[j]) { :
missing value where TRUE/FALSE needed
Enter a frame number, or 0 to exit
1: test()
Selection: 1
Called from: eval(expr, envir, enclos)
Browse[1]> ls()
[1] "i" "j" "vector1" "vector2"
Browse[1]> vector1
[1] 27 37 57 89 20 86 97 62 58 6
Browse[1]> vector2
[1] 21 18 68 38 74 48 98 93 35 71
Browse[1]> vector1[27]
[1] NA
Browse[1]>
Notice that vector1 is only 10 long and then you try to address
vector1[27] you get an NA
On Fri, Nov 7, 2008 at 7:22 PM, David Croll <david.croll at gmx.ch> wrote:
> Hello dear R people,
>
>
> for my MSc thesis I need to program some functions, and some of them simply
> do not work. In the following example, I made sure both vectors have the
> same length (10), but R gives me the following error:
>
> Error in if (vector1[i] == vector2[j]) { :
> missing value where TRUE/FALSE needed
>
> I googled for possible solutions, but I did not find a good explanation for
> this...
>
>
> The code:
>
> test <- function() {
> vector1 <- sample(1:100,10)
> vector2 <- sample(1:100,10)
> for (i in vector1) {
> for (j in vector2) {
> if (vector1[i] == vector2[j]) {
> show(list(i,j))
> }
> }
> }
> }
>
> Regards, David
>
> ______________________________________________
> 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