From MSchwartz at mn.rr.com  Thu Oct 20 03:28:05 2005
From: MSchwartz at mn.rr.com (Marc Schwartz)
Date: Wed, 19 Oct 2005 20:28:05 -0500
Subject: [Rd] is.na<- problem
In-Reply-To: <971536df0510191809v3a7cd3d0k753e95a71be027d3@mail.gmail.com>
References: <XFMail.051020011342.Ted.Harding@nessie.mcc.ac.uk>
	<1129769164.5955.5.camel@localhost.localdomain>
	<971536df0510191809v3a7cd3d0k753e95a71be027d3@mail.gmail.com>
Message-ID: <1129771685.5955.12.camel@localhost.localdomain>

On Wed, 2005-10-19 at 21:09 -0400, Gabor Grothendieck wrote:
> On 10/19/05, Marc Schwartz <MSchwartz at mn.rr.com> wrote:
> > On Thu, 2005-10-20 at 01:13 +0100, Ted Harding wrote:
> > > On 19-Oct-05 Gabor Grothendieck wrote:
> > > > In the following the first element of xx should have
> > > > been set to 0 but remains NA.  Any comments?
> > > >
> > > >> xx <- c(NA,1)
> > > >> is.na(xx) <- 0
> > > >> xx
> > > > [1] NA  1
> > > >> R.version.string # Windows XP
> > > > [1] "R version 2.2.0, 2005-09-20"
> > >
> > > I wonder, has it ever worked? I get the same as you on
> > >
> > > R.version.string #Linux
> > > [1] "R version 1.6.2, 2003-01-10"
> > >
> > > R.version.string #Linux
> > > [1] "R version 1.8.0, 2003-10-08"
> > >
> > > R.version.string #Linux
> > > [1] "R version 2.1.0, 2005-04-08"
> > >
> > > with the exception of
> > >
> > > R.version.string #Linux
> > > [1] "R version 1.2.3, 2001-04-26"
> > >
> > > which does know about is.na()<- at all.
> > >
> > >
> > > Hmmm
> > > Ted.
> >
> > According to the documentation in ?is.na:
> >
> >   The generic function is.na<- sets elements to NA.
> >
> > and in the details section:
> >
> > Function is.na<- may provide a safer way to set missingness. It behaves
> > differently for factors, for example.
> >
> >
> > In reviewing the Green Book on the top of page 143, it shows an example
> > in which the RHS of the assignment are the indices into the LHS object
> > which are to be set to NA. For example:
> >
> > > xx <- c(0:5)
> >
> > > xx
> > [1] 0 1 2 3 4 5
> >
> > > is.na(xx) <- c(3, 4)
> >
> > > xx
> > [1]  0  1 NA NA  4  5
> >
> >
> > Thus, back to Gabor's example, the proper approach would of course be:
> >
> > > xx <- c(NA,1)
> >
> > > xx
> > [1] NA  1
> >
> > > xx[is.na(xx)] <- 0
> >
> > > xx
> > [1] 0 1
> >
> >
> > HTH,
> >
> > Marc Schwartz
> >
> >
> >
> 
> 
> Thanks.  I actually had read ?is.na but obviously not closely enough.

Happy to help.

In all honesty, while I understood the concept from reading the help
page, it was not truly clear until I read the Green Book and saw the
example as to how to actually use the function.

It would probably be worthwhile to add an example of use to the help
page.

Best regards,

Marc



[Rd] is.na<- problem
Marc Schwartz