Skip to content
Back to formatted view

Raw Message

Message-ID: <1337096753351-4630118.post@n4.nabble.com>
Date: 2012-05-15T15:45:53Z
From: math_daddy
Subject: Odd behaviour of identical()

Consider the following code:

test <- function(n)
{
  for(x in 1:n)
  {
    for(y in 1:n)
    {
      for(r in max(x-1,1):min(x+1,n))
      {
        for(s in max(y-1,1):min(y+1,n))
        {
          vec <- c(x-r,y-s)
          print(c("vec = ", vec))
          print(identical(vec,c(0,0)))
        } 
      }
    }
  } 
}

If you run test(2) you'll see a printout of the values of the vector vec
followed by a logical telling you whether vec is identical to c(0,0), which
it will be for certain iterations of the nested loop. However, the logical
is always FALSE. If I don't perform the loop but instead assign the values
directly to vec, this problem does not arise. Can anyone tell me what is
happening here? 

Thank you very much in advance for any help.


--
View this message in context: http://r.789695.n4.nabble.com/Odd-behaviour-of-identical-tp4630118.html
Sent from the R help mailing list archive at Nabble.com.