Please see Sam Buttrey's quick reply -- to the point, to my question. I
apologize for the non-specificity of the original message title.
Don McKenzie
---------- Forwarded message ----------
Date: Tue, 11 Dec 2001 10:02:12 -0800
From: "Buttrey, Samuel" <sebuttre@nps.navy.mil>
To: 'D. Mckenzie' <dmck@U.WASHINGTON.EDU>
Subject: RE: [S] either this is a bug or I'm missing something...
Hi Don,
Remember that S-Plus "recycles" numbers when it compares two vectors of
different lengths. In this case it uses "temp" three times, so it's
comparing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
and
7 8 11 12 19 20 23 24 7 8 11 12 19 20 23 24 7 8 11 12 19 20 23 24,
which are not equal at these spots
x x x x x x x x x x x x x x x x x x x
x ,
and these are the indices you're seeing reported.
I'm not sure what your underlying problem is, but I've found is.element() to
be very useful:
is.element (temp, 1:24) gives a vector of 8 TRUEs indicating that every
element in temp is also in 1:24;
is.element (1:24, temp) gives a vector of 8 TRUEs and 16 FALSEs, showing the
places in 1:24 in which elements of temp appear.
Of course match() is indispensible in some contexts, too.
Have fun,
Sam Buttrey
-----Original Message-----
From: D. Mckenzie [mailto:dmck@u.washington.edu]
Sent: Tuesday, December 11, 2001 9:55 AM
To: s-news group
Subject: [S] either this is a bug or I'm missing something...
S> temp <- c(7,8,11,12,19,20,23,24)
The first command produces expected behavior
S> c(1:24)[match(c(1:24),temp) == "NA"]
[1] 1 2 3 4 5 6 9 10 13 14 15 16 17 18 21 22
But this one...?
S> c(1:24)[c(1:24) != temp]
[1] 1 2 3 4 5 6 7 8 9 10 13 14 15 16 17 18 19 20 21 22
Is this a type of many-to-one relation that I misunderstand?
Thanks.
_______________________________________________________________________
DON MCKENZIE
Research Ecologist
College of Forest Resources, Box 352100
University of Washington
Seattle, WA 98195
206.616.4095
dmck@u.washington.edu
_______________________________________________________________________
---------------------------------------------------------------------
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
|