Skip to content
Prev 67884 / 398503 Next

array indexing and which

On Sun, 2005-04-17 at 19:13 +0200, Werner Wernersen wrote:
Having a reproducible example, as per the posting guide, would be
helpful here. We'll use a contrived example that hopefully explains what
I can only presume you are seeing.
Here ids contains the indices of the values in the vector d[, 1] that
are > 0.

For example:
[,1] [,2]
[1,]    1    1
[2,]    1    1
[3,]    0    1
[4,]    0    0
[5,]    0    1
[6,]    1    0
[1] 1 2 6

Note that c(1, 2, 6) are the indices into the vector:
[1] 1 1 0 0 0 1

of the values that are > 0.
Here ids2 contains the indices of the values in gk[ids] that equal 1.
[1] 1 1 1 0 1 1
[1] 1 1 1
[1] 1 2 3

All three of the values in gk[ids] == 1.
Here you are getting the result of logically comparing the two vectors:
[1]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE

AND
[1]  TRUE  TRUE FALSE FALSE FALSE  TRUE


where the result of the comparison is the index value of each pair in
the two vectors where both values are TRUE.

Thus:
[1] 1 2 6

versus:
[1] 1 2 3
It's not wrong. It is giving you what you asked for.

Your question was wrong.  :-)
HTH,

Marc Schwartz