Re: [R] While loop working with TRUE/FALSE?

2012-02-02 Thread Chris82
Thanks to Berend and the others, I've found a solution which works fine for my problem. I have not only 2 vectors, but also 4. Question is, if q1 and q2 is equal to w1 and w2. The computational time is very short, also for large data. q1 - c(9,5,1,5) q2 - c(9,2,1,5) w1 - c(9,4,4,4,5) w1 -

Re: [R] While loop working with TRUE/FALSE?

2012-02-02 Thread Patrizio Frederic
Hey Chris, I would take advantage from the apply function: apply(cbind(q1,q2),1,function(x)any((x[1]==w1)(x[2]==w2))) Regards PF On Thu, Feb 2, 2012 at 12:55 PM, Chris82 rubenba...@gmx.de wrote: Thanks to Berend and the others, I've found a solution which works fine for my problem. I have

Re: [R] While loop working with TRUE/FALSE?

2012-02-02 Thread David Winsemius
On Feb 2, 2012, at 6:55 AM, Chris82 wrote: Thanks to Berend and the others, I've found a solution which works fine for my problem. I have not only 2 vectors, but also 4. Question is, if q1 and q2 is equal to w1 and w2. The computational time is very short, also for large data. q1 -

Re: [R] While loop working with TRUE/FALSE?

2012-02-02 Thread Petr PIKAL
Hi Thanks to Berend and the others, I've found a solution which works fine for my problem. I have not only 2 vectors, but also 4. Question is, if q1 and q2 is equal to w1 and w2. The computational time is very short, also for large data. q1 - c(9,5,1,5) q2 - c(9,2,1,5) w1 -

[R] While loop working with TRUE/FALSE?

2012-02-01 Thread Chris82
Hi R users, is there any possibilty that a while loop is working like that: z - c(0,1,2,3,4,5,6,7,8,9) r - 7 while(w == T) { for ( i in 1:10 ){ w - r == z[i] print(w) } } The loop should stop if w == TRUE best regards -- View this

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread R. Michael Weylandt
You are combining too many loop constructs: perhaps you just want to use for and break. Of course, in your case it's much faster to write which(r == z) or which.min(r == z) Michael On Wed, Feb 1, 2012 at 10:55 AM, Chris82 rubenba...@gmx.de wrote: Hi R users, is there any possibilty that a

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Milan Bouchet-Valat
Le mercredi 01 février 2012 à 07:55 -0800, Chris82 a écrit : Hi R users, is there any possibilty that a while loop is working like that: z - c(0,1,2,3,4,5,6,7,8,9) r - 7 while(w == T) { for ( i in 1:10 ){ w - r == z[i] print(w) }

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Berend Hasselman
On 01-02-2012, at 16:55, Chris82 wrote: Hi R users, is there any possibilty that a while loop is working like that: z - c(0,1,2,3,4,5,6,7,8,9) r - 7 while(w == T) { for ( i in 1:10 ){ w - r == z[i] print(w) } } The loop should

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Chris82
Thanks to both. This is just a simple example. In real I have two vectors with different lengths. The code consists of two for loops for r and z. The main problem is the computational time, so I try to stop the loop if w is TRUE for the first time. First I tried to use the command stop in

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Jeff Newmiller
No. The while loop is only tested after the for loop has completed. Use debug to understand this if it doesn't make sense to you. --- Jeff NewmillerThe . . Go Live...

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Feng Li
I guess you want something like w=F z - c(0,1,2,3,4,5,6,7,8,9) r - 7 while(w == F) { for ( i in 1:10 ){ w - r == z[i] print(w) } } But this loop will run forever. The condition for while is checked when i jumps from 10 to 1. At that moment w

Re: [R] While loop working with TRUE/FALSE?

2012-02-01 Thread Berend Hasselman
On 01-02-2012, at 17:32, Chris82 wrote: Thanks to both. This is just a simple example. In real I have two vectors with different lengths. The code consists of two for loops for r and z. The main problem is the computational time, so I try to stop the loop if w is TRUE for the first