RE: [R] array indexing and which

From: <Bill.Venables_at_csiro.au>
Date: Mon 18 Apr 2005 - 08:54:51 EST


You need to think about it just a bit harder.

[Hint: what happens if you leave out the first 'which' and just make

ids <- (d[, 1] > 0)

does it work then...?]

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Werner Wernersen
Sent: Monday, 18 April 2005 3:13 AM
To: r-help@stat.math.ethz.ch
Subject: [R] array indexing and which

Hi R friends!

I am stuck with a stupid question: I can circumvent it but I would like to
understand why it is wrong. It would be nice if you could give me a hint...

I have an 2D array d and do the following: ids <- which(d[,1]>0)

then I have a vector gk with same column size as d and do:
ids2 <- which(gk[ids]==1)

but I can't interprete the result I get in ids2.

I get the expected result when I use:
which(gk==1 & d[,1]>0)

Why is the first version wrong?

The reason why I try to use the ids vectors is that I want to avoid recomputation.

Thanks for your help!

   Werner



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Apr 18 11:11:07 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:14 EST