[R] While loop working with TRUE/FALSE?

Berend Hasselman bhh at xs4all.nl
Wed Feb 1 18:55:29 CET 2012


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
> time.
> 

Maybe this helps:

z <- c(0,1,2,3,4,5,6,7,8,9)
r <- c(3,7)

fun1 <- function(r, z) sapply(r,function(x) which(x == z))
fun1(r,z)

Berend



More information about the R-help mailing list