Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.LNX.4.44.0304251632340.13071-100000@gannet.stats>
Date: 2003-04-25T15:34:47Z
From: Brian Ripley
Subject: Code bug unresolved involving if condition
In-Reply-To: <OFD453E56B.54A9F86E-ONC1256D13.00530B0D@ges.marc.societe-generale.fr>

The message is both pleasant and accurate!  It indicates that you have 
made an error, and tells you what the error is.

foo == NA is always missing, since NA denotes a missing value.
Use is.na(foo): see ?is.na.

On Fri, 25 Apr 2003 vincent.stoliaroff at socgen.com wrote:

> Hi R lovers!
> 
> I am a beginner in coding with R so my question may be very easily solved
> but I don't know how.
> 
> I have written the following function in a .txt file
> 
> 
> ClearDelta <- function(Matrix)
> {
> ncol<-ncol(Matrix);nrow<-nrow(Matrix);
> for (i in 1:nrow) {
>                   for (j in 1:(ncol-1))
>                         {if (Matrix[i,j]==NA) (NA->Matrix[i,j+1])}
>                   }
> }
> 
> I can charge it with the source() command
> But I get the following message when applied to a matrix
> 
> > ClearDelta(MatCor)
> Error in if (Matrix[i, j] == NA) (Matrix[i, j + 1] <- NA) :
>         missing value where logical needed
> 
> MatCor is the following Matrix
> 
> > MatCor
>            [,1]         [,2]       [,3]
> [1,]         NA          0.9870676  0.04648933
> [2,] 0.98706757  1.0000000 -0.17353590
> [3,] 0.04648933 -0.1735359  1.00000000
> 
> Do you know why I get such an unpleasant message from so polite a software?
> 
> Thanks to anybody who could help.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595