Just a few footnotes by a cranky old curmudgeon...
> -----Original Message-----
> From: Timothy J. Wade [mailto:tjwade@uclink4.berkeley.edu]
> Sent: Friday, 1 December 2000 6:51
> To: Marion VERDOIT; S-news@wubios.wustl.edu
> Subject: Re: [S] (pas d'objet)
>
>
> Sorry, correction:
>
> Try this:
> a <- c("NA","1", "NA", "5", "NA", "6","8","10")
> x <- c(1:length(a))
This is not a hanging offence, but the c() is entirely unnecessary here.
Including such things in public code tends to confuse people and to start
off littel myths and prejudices.
x <- 1:length(a) ## is OK but
x <- seq(along = a) ## can sometimes be safer.
>
> **z<-x[a=="NA"]** NOT z<-z[a=="NA"]
True but you could also
z <- seq(along = a)[is.element(a, "NA")]
for example and do it in one neat step, without becoming all that
obfuscated.
>
> At 06:37 PM 11/30/2000 +0100, Marion VERDOIT wrote:
> >Hello,
> >I have a vector
> >a<-c("NA","1", "NA", "5", "NA", "6","8","10")
> >I want the positions of the "NA"s in a, i.e.:
> >1 3 5
> >I try
> >match("NA", a), but it returns only the first position :
> > > 1
> >have you the solution?
Nearly. You put the arguments to match() the wrong way round.
match(a, "NA")
would have just about got you there. The is.element() function is really
just a front end to match for people who forget which way round to put the
arguments!
Bill Venables.
> >Thank you
> >---------------------------------------------------------------------
> >This message was distributed by s-news@lists.biostat.wustl.edu. To
> >unsubscribe send e-mail to
> s-news-request@lists.biostat.wustl.edu with
> >the BODY of the message: unsubscribe s-news
>
> ---------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
>
>
> ---------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
>
|